-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (56 loc) · 1.62 KB
/
index.js
File metadata and controls
64 lines (56 loc) · 1.62 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
const express = require('express');
const pmx = require('pmx');
const Db = require('./helpers/Db');
pmx.init({
http: true, // HTTP routes logging (default: true)
errors: true, // Exceptions loggin (default: true)
custom_probes: true, // Auto expose JS Loop Latency and HTTP req/s as custom metrics
network: true, // Network monitoring at the application level
});
const http = require('http');
const bodyParser = require('body-parser');
const favicon = require('serve-favicon');
const compress = require('compression');
const chalk = require('chalk');
const morgan = require('morgan');
const config = require('./config/config');
const log = require('./helpers/log');
const router = require('./helpers/router');
const cors = require('cors');
const corsOptions = {
origin: '*',
credentials: true,
allowedHeaders: [
'Content-Type',
'Authorization',
'Content-Length',
'X-Requested-With',
'X-HTTP-Method-Override',
],
methods: [
'GET', 'OPTIONS',
],
};
// const httpsOptions = {
// key: fs.readFileSync('./config/key.pem'),
// cert: fs.readFileSync('./config/cert.pem'),
// };
const app = express();
app
.use(compress())
.use(favicon('./public/favicon.ico'))
.use(morgan(config.logger.express))
.use(express.static('public'))
.use(bodyParser.json())
.use(bodyParser.urlencoded({
extended: true,
}))
.use(cors(corsOptions));
http.createServer(app).listen(config.server.port);
// Create the DB connection
Db.connect()
.then(() => {
log(chalk.bgBlue('🔛 [SERVER] Express listening http ' +
`on ${config.server.port} `));
router(app);
});