blob: fcc4a28cb467c76fe21ef4cc33690ccd83238514 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import express from 'express';
import { registerRoutes } from './routes.js';
import { useAuthentication, useCors, useLogging } from './middlewares/index.js';
import { initDb } from '#db/index.js';
import { initJwt } from '#util/index.js';
import { handleErrors } from '#api/middlewares/errorMiddleware.js';
const app = express();
const PORT = process.env.PORT ?? 3000;
const logRequests = process.env['LOG_REQUESTS'] ?? '-';
await initDb();
await initJwt();
// Configure Express
app.use(express.json());
app.use(useCors);
app.use(useAuthentication);
app.disable('x-powered-by');
app.set('json spaces', 2);
if (logRequests) {
app.use(useLogging(logRequests));
}
registerRoutes(app);
app.use(handleErrors);
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
|