-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-server.ts
51 lines (38 loc) · 1.28 KB
/
start-server.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node --experimental-specifier-resolution=node
// import * as dotenv from "dotenv";
import cors from "cors";
import { EventEmitter } from 'events';
import express, { Request, Response } from "express";
import { KissServer } from "kiss-framework";
import { config } from "./config.js";
export function tictoc(msg = '') {
const tic = {start: new Date().getTime(), msg}
return {
toc: (msg = '') => {
const toc = new Date().getTime();
const interval = toc - tic.start;
console.log(`${interval / 1000.0}s ${tic.msg} ${msg}`);
return interval
}
}
}
const logger = (req: Request, res: Response, next: Function) => {
const tic = tictoc()
next();
const clientIp = req.ip;
//signale.debug("%s %s %s", clientIp, req.method, req.url, req.path);
tic.toc(`${clientIp}, ${req.method}, ${req.url}, ${req.path} status: ${res.statusCode}`)
};
// clear console, quite nice when nodemon is running
// console.clear();
// configure Event Emitter
EventEmitter.defaultMaxListeners = 300;
// configure express
const app = express();
// configure cors
app.use(cors());
// configure body parser
app.use(express.json()); // for parsing application/json
app.use(logger);
// app.use(express.static(config.staticRoute))
new KissServer(app, config);