BIG BANG
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*.db
|
||||||
|
node_modules
|
||||||
|
build
|
||||||
20
package.json
Normal file
20
package.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "albion-online-transaction-tracker-server",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"type": "commonjs",
|
||||||
|
"scripts": {
|
||||||
|
"build": "esbuild src/main.ts --bundle --outfile=build/out.js --platform=node --external:better-sqlite3"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/better-sqlite3": "^7.6.12",
|
||||||
|
"@types/express": "^5.0.1",
|
||||||
|
"better-sqlite3": "^11.9.1",
|
||||||
|
"esbuild": "^0.25.2",
|
||||||
|
"express": "^5.1.0",
|
||||||
|
"ts-node": "^10.9.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
1312
pnpm-lock.yaml
generated
Normal file
1312
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
src/main.ts
Normal file
21
src/main.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import express from 'express';
|
||||||
|
import Database from 'better-sqlite3';
|
||||||
|
import prepareDB from './prepare';
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
app.get("/tiers", (req, res) => {
|
||||||
|
const db = new Database('store.db', { verbose: console.log });
|
||||||
|
res.status(200);
|
||||||
|
res.set("Content-Type", "application/json");
|
||||||
|
res.send((db.prepare("SELECT * FROM tiers").all() as { tier: number}[]).map(t => t.tier));
|
||||||
|
db.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(2500, () => {
|
||||||
|
console.log("Server is running");
|
||||||
|
})
|
||||||
|
|
||||||
|
const db = new Database('store.db', { verbose: console.log });
|
||||||
|
prepareDB(db);
|
||||||
|
|
||||||
|
db.close()
|
||||||
11
src/prepare.ts
Normal file
11
src/prepare.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import Database from "better-sqlite3";
|
||||||
|
|
||||||
|
export default function prepareDB(db: Database.Database) {
|
||||||
|
db.exec("CREATE TABLE IF NOT EXISTS tiers (tier INT PRIMARY KEY);");
|
||||||
|
|
||||||
|
for (let i = 1; i <= 8; i++) {
|
||||||
|
if (!db.prepare(`SELECT tier FROM tiers WHERE tier = ${i};`).pluck().get()) {
|
||||||
|
db.prepare("INSERT INTO tiers VALUES (?)").run(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user