-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
42 lines (34 loc) · 1.15 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
const express = require('express'),
cors = require('cors'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
config = require('konfig')().app,
cookieParser = require('cookie-parser'),
Logger = require('./logger');
const app = express();
const log = new Logger(app);
app.use(cors({ origin: '*' }));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride('X-HTTP-Method-Override'));
const PublicAPIController = require('./controllers')();
app.use('/api', new PublicAPIController(config).setupRouter(express.Router()));
app.use(express.static('public'));
app.get("*", function (request, response) {
response.sendFile(__dirname + '/public/index.html');
});
//handle HTTP errors
app.use(function(err, req, res, next) {
console.log(err);
if(!res.headersSent){
res
.status(err.statusCode || 500)
.send(err.message)
.end();
}
});
// listen for requests :)
var listener = app.listen(process.env.PORT, function () {
console.log('Your app is listening on port ' + listener.address().port);
});