-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
34 lines (24 loc) · 777 Bytes
/
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
const express = require('express');
// const bodyParser = require('body-parser');
const createEndpoints = require('./endpoints');
function createApp() {
const app = express();
// Initialize middleware and router...
// Authentication
// E.g. passport
// Logging
// E.g. morgan or winston
// Data parsing and transformation
// E.g. body-parser
// app.use(bodyParser.json())
// Route handling
app.use('/example', createEndpoints());
// Error handling middleware
// It requires a 4 parameter handler
app.use((err, req, res, next) => {
console.log("Oops, caught an error: ", err.message);
res.status(500).send("There seems to have been an error");
})
return app;
}
module.exports = createApp;