-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (44 loc) · 1.19 KB
/
app.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
const express = require('express');
const cors = require('cors');
const path = require('path');
const logger = require('./loaders/logger');
const config = require('./config');
const routes = require('./api');
const bodyParser = require('body-parser');
const app = express();
/* Configuring Application */
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.json());
app.use(cors());
app.set('x-powered-by', false);
/* Configuring Routes */
app.get('/status', (req,res) => {
res.status(200).end();
})
app.head('/status', (req,res) => {
res.status(200).end();
});
app.use(config.api.prefix, routes());
/* Error Handling */
app.use((err, req, res, next) => {
logger.error(err, err.stack);
res.status(500).send({error: "Internal Server Error!"});
next;
});
process.on('unhandledRejection', err => {
logger.error(err, err.stack);
// logger.error(err.message, {err});
throw err;
});
/* Start Server */
(async () => {
await new Promise((resolve, reject) => {
require('http')
.createServer(app)
.listen(config.port, resolve)
.on('error', reject);
});
logger.info('🔰 Server started on port 3000 🔰');
})();