-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (25 loc) · 820 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
32
const express = require('express');
const boom = require('express-boom');
const Boom = require('boom');
const morgan = require('morgan');
const mainRouter = require('./routes/main');
// By default, set the HTTP port to 3000
const port = process.env.PORT || 3000
// Initialise express
const app = express()
// Log requests
app.use(morgan('combined'))
// Use the main router to route requests
app.use('/', mainRouter)
// Handle any missing resources
app.use(function (req, res, next) {
res.json(Boom.notFound('The specified resource was not found'));
})
app.use(function (err, req, res, next) {
console.error(err.stack)
res.json(Boom.badImplementation('Something went wrong'));
})
// Listen on specified port
app.listen(port, () => {
console.log('Application started listening on port ' + port)
});