-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (25 loc) · 869 Bytes
/
index.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
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const port = process.env.PORT || 3000
app.use(bodyParser.json())
app.disable('etag')
const normalizedPath = require("path").join(__dirname, "routes");
require("fs").readdirSync(normalizedPath).forEach(function(file) {
require("./routes/" + file)(app);
});
app.use(function(err, req, res, next) {
console.error({err: err, message: err.message, errName: err.name, stack: err.stack}, 'Uncaught server error');
res.status(500).json({message: 'Something went wrong.'});
})
if( process.env.NODE_ENV != 'production' && module.parent ) {
module.exports = function(port) {
const ref = app.listen(port)
const handle = ref.close.bind(ref)
return handle
}
return
}
app.listen(port, function() {
console.log(`Listening on ${port}...`)
})