24 lines
778 B
JavaScript
24 lines
778 B
JavaScript
import dotenv from 'dotenv';
|
|
import express from 'express';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import apiRouter from './api.js';
|
|
dotenv.config();
|
|
|
|
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.json())
|
|
app.use(express.urlencoded({ extended: true }))
|
|
//app.use(express.static(path.join(__dirname, "public"), {
|
|
// dotfiles: "ignore"
|
|
//}));
|
|
app.use("/api", apiRouter);
|
|
|
|
const server = app.listen(5555, () => {
|
|
console.log(`Server running on http://localhost:${server.address().port}`);
|
|
}); |