-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb-server.ts
More file actions
39 lines (30 loc) · 889 Bytes
/
web-server.ts
File metadata and controls
39 lines (30 loc) · 889 Bytes
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
38
39
import express from 'express';
import RateLimit from 'express-rate-limit';
import bodyParser from 'body-parser';
import morgan from 'morgan';
import { logError } from '@arken/node/log';
const path = require('path');
function initRoutes(server) {
try {
server.get('/hello', (req, res) => res.end('world'));
} catch (e) {
logError(e);
}
}
export async function initWebServer(server) {
console.log('Init web server');
// @ts-ignore
const rateLimiter = new RateLimit({
windowMs: 2,
max: 5,
});
// Accept json and other formats in the body
server.use(bodyParser.urlencoded({ extended: true }));
server.use(bodyParser.json());
// Apply ratelimit
server.use(rateLimiter);
// Logging
server.use(morgan(process.env.NODE_ENV === 'production' ? 'combined' : 'dev'));
server.use(express.static(path.resolve('./public')));
initRoutes(server);
}