-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
37 lines (29 loc) · 1.24 KB
/
app.js
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
33
34
35
36
37
import log from "./utils/log.js";
log.inf("Loading packages and middleware...");
import express from "express";
import bodyParser from "body-parser";
import { dirname } from 'path';
import path from 'path';
import { fileURLToPath } from 'url';
import request from "./middleware/request.js";
import routing from "./middleware/routes.js";
log.inf("Configuring middleware...");
global.port = 8081;
const __dirname = dirname(fileURLToPath(import.meta.url));
const app = express();
app.use(request.logging());
app.use(request.cors);
app.enable("trust proxy");
app.use("/api/", request.rateLimit());
app.use(request.filterNonApiRequests(__dirname));
app.use('/js', express.static(path.join(__dirname, 'dist/js')));
app.use('/css', express.static(path.join(__dirname, 'dist/css')));
app.use('/img', express.static(path.join(__dirname, 'dist/img')));
app.use('/assets', express.static(path.join(__dirname, 'dist/assets')));
app.use('/fonts', express.static(path.join(__dirname, 'dist/fonts')));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
log.inf("Setting up routing...");
await routing.setUpRouting(app);
log.inf("App setup finish. Starting server...");
app.listen(global.port, _ => log.suc("Server running on port " + global.port));