-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (24 loc) · 982 Bytes
/
app.js
File metadata and controls
34 lines (24 loc) · 982 Bytes
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
import bodyParser from 'body-parser';
import express from 'express';
import favicon from 'serve-favicon';
import path from 'path';
import cors from 'cors';
import errorController from './controllers/errors';
import logger from './utils/logger';
import routes from './routes';
const app = express();
// add cors - "Access-Control-Allow-Origin", "*" by default
app.use(cors());
// make models available globally in engine
app.set('models', require('./models'));
app.use(bodyParser.json({ limit: '1mb' })); // sets payload limit
app.use(bodyParser.urlencoded({ extended: false })); // url encoding
app.use(express.static(path.join(__dirname, 'public'))); // sets a static route to public
// Set up routes
Object.keys(routes).forEach((route) => {
logger.info(`setting up route /${route} to file ${routes[route]}`);
app.use(`/${route}`, require(`${routes[route]}`).default);
});
// Handle 404s
app.use((req, res) => errorController.notFound(req, res));
export default app;