-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
69 lines (59 loc) · 1.46 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
// const passport = require('passport');
import path from 'path';
import fs from 'fs';
const router = express.Router();
const app = express();
import dotenv from 'dotenv'
dotenv.config()
const port = process.env.PORT || 5050;
/**
* Middleware
*/
app.use(cors())
app.use(bodyParser.json({ limit: '50mb' }));
app.use(
bodyParser.urlencoded({
limit: '50mb',
extended: true,
parameterLimit: 50000,
})
);
app.use(bodyParser.json());
// /**
// * JWT Auth
// */
// app.use(passport.initialize());
// require('./auth/passport')(passport);
/**
* Routes
*/
import {router as functions} from './index.js';
app.use('/', functions);
// Online check
app.use(
'/',
router.get('/', (req, res) => {
try {
res.json({ res: 'success' });
} catch (err) {
res.json({ res: err });
}
})
);
//Change to server.listen(...) for https
app.listen(port, '0.0.0.0', err => {
if (err) throw err;
console.log(`Server is running on port: ${port}`);
});
const exitHandler = (exitCode, options) => {
console.log('Shutting down');
process.exit();
};
process.on('exit', exitHandler.bind(null, { exit: true }));
process.on('SIGINT', exitHandler.bind(null, { exit: true }));
process.on('SIGUSR1', exitHandler.bind(null, { exit: true }));
process.on('SIGUSR2', exitHandler.bind(null, { exit: true }));
process.on('uncaughtException', exitHandler.bind(null, { exit: true }));