-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
50 lines (35 loc) · 986 Bytes
/
server.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
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
import express from 'express';
import path from 'path';
import cors from 'cors';
import dotenv from 'dotenv';
const __dirname = path.resolve(path.dirname(''));
dotenv.config()
// Constants
const PORT = process.env.PORT || 3000;
const HOST = '0.0.0.0';
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
app.get('/', async (req, res) => {
res.sendFile(__dirname + '/static/index.html');
});
app.get('/pool', async (req, res) => {
res.status(200).send('OK');
});
app.post('/test1', (req, res) => {
// new usageStats(req, res).getLimitUsage();
})
console.log(`'HTTP server started' on port ${PORT}`);
const server = app.listen(+PORT, HOST,()=>{});
function closeGracefully(signal) {
server.close(() => {
console.log(`'HTTP server closed'`)
})
}
process.on('SIGTERM', closeGracefully)