forked from Govindraj786/RPMDoctor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (36 loc) · 1.11 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
require('dotenv').config();
// Node/Express
const express = require('express');
const http = require('http');
const path = require('path');
const bodyParser = require('body-parser');
const router = require('./src/router');
const syncServiceDetails = require('./src/sync_service_details');
// Create Express webapp
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
const cors = require('cors');
app.use(cors());
// Add body parser for Notify device registration
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(router);
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
console.trace(err);
res.status(err.status || 500);
res.send({
message: err.message,
error: {},
});
});
// Get Sync Service Details for lazy creation of default service if needed
syncServiceDetails();
// Create http server and run it
const server = http.createServer(app);
const port = process.env.PORT || 5000;
server.listen(port, function() {
console.log('Express server running on *:' + port);
});
module.exports = app;