implement basic express server + api
This commit is contained in:
@@ -1,5 +1,22 @@
|
||||
import dotenv from 'dotenv';
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import apiRouter from './api.js';
|
||||
dotenv.config();
|
||||
const db = await import('./db.js');
|
||||
|
||||
db.initDB();
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.join(path.dirname(__filename), ".."); // going back a dir cuz code is in src/
|
||||
const db = await import('./db.js'); // dynamic import because otherwise dotenv will not work correctly
|
||||
const app = express();
|
||||
|
||||
db.initDB();
|
||||
|
||||
app.use(express.static(path.join(__dirname, "public"), {
|
||||
dotfiles: "ignore"
|
||||
}));
|
||||
app.use("/api", apiRouter);
|
||||
|
||||
const server = app.listen(0, () => {
|
||||
console.log(`Server running on http://localhost:${server.address().port}`);
|
||||
});
|
||||
Reference in New Issue
Block a user