-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathserver.js
More file actions
65 lines (52 loc) · 1.67 KB
/
server.js
File metadata and controls
65 lines (52 loc) · 1.67 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
import express from 'express';
import http from 'http';
import path from 'path';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import {routing} from "./routes/_.js";
import {update} from "./netTools/middleware.js";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const packageJSON = require("./package.json");
const rootDir = 'dist';
const app = express();
const jsonParser = bodyParser.json({
limit: '50mb'
});
const configureExpress = function () { return new Promise((resolve, reject) => {
app.disable('x-powered-by');
app.use(express.static(rootDir));
app.set('views', path.join(rootDir, 'views'));
app.set('view engine', 'pug');
app.use(cookieParser());
app.use(bodyParser.urlencoded({extended: true}));
return resolve();
}); };
const configureRouting = function () { return new Promise((resolve, reject) => {
app.get('/*', update);
app.delete('/*', update);
app.post('/*', jsonParser, update);
routing(app, jsonParser);
return resolve();
}); };
const launch = function () { return new Promise((resolve, reject) => {
const port = 8081;
const server_http = http.createServer(app);
server_http.listen(port, (err) => {
if (err) {
return reject(err);
}
return resolve();
});
}); };
configureExpress()
.then(configureRouting)
.then(launch)
.then(() => {
console.log('\x1b[4m' + packageJSON.name + '\x1b[0m started.');
console.log('______________________________________________________________________');
}).catch((err) => {
console.error(err);
process.exit(1);
})