diff --git a/dotenv-template b/dotenv-template deleted file mode 100644 index 787b1ec..0000000 --- a/dotenv-template +++ /dev/null @@ -1,3 +0,0 @@ -MONGO_URI = "A URI to the mongodb database." -PORT = 12345 -LOAD_DB = true | false \ No newline at end of file diff --git a/index.js b/index.js index 8389b21..f63cf69 100644 --- a/index.js +++ b/index.js @@ -10,12 +10,23 @@ import njk from 'nunjucks' import initLog from './libs/utils/log.js' import routes from './routes/routes.js' +import api from './api/api.js' + +import { generateDB } from './libs/database/generate.js' +import { dbInit } from './libs/database/init.js' +import { downloadEssentialData } from './libs/download/dowload.js' const log = initLog("[ MAIN ]") // Read the .env file dotenv.config() +if (process.env.DOWNLOAD_FILES === "true") + await downloadEssentialData() + +dbInit() +generateDB() + const Server = express() njk.configure( @@ -29,6 +40,7 @@ njk.configure( ) Server.use('/', routes) +Server.use('/api', api) Server.use('/assets', express.static('static')) Server.listen(process.env.PORT ?? 12345, () => log(`Server started and listening on port ${process.env.PORT}.`)) diff --git a/libs/database/generate.js b/libs/database/generate.js index 0293681..f1704f4 100644 --- a/libs/database/generate.js +++ b/libs/database/generate.js @@ -162,7 +162,7 @@ export function generateDB() { log("Generating map index...") execMany([ `CREATE INDEX IF NOT EXISTS "idx_maps_map" ON "maps" ("map")`, - `CREATE INDEX IF NOT EXISTS "idx_maps_category" ON "maps" ("category")` + `CREATE INDEX IF NOT EXISTS "idx_maps_category" ON "maps" ("category")`, `CREATE INDEX IF NOT EXISTS "idx_maps_categoryMap" ON "maps" ("category", "map")` ]) diff --git a/package.json b/package.json index a12bf5d..bade835 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,10 @@ "license": "WTFPL", "dependencies": { "@msgpack/msgpack": "^2.7.1", + "better-sqlite3": "^7.4.4", "dotenv": "^10.0.0", "express": "^4.17.1", - "mongoose": "^6.0.11", - "nunjucks": "^3.2.3", - "sqlite": "^4.0.23", - "sqlite3": "^4.2.0" + "nunjucks": "^3.2.3" }, "nodeVersion": "system" }