-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (26 loc) · 1.02 KB
/
app.js
File metadata and controls
35 lines (26 loc) · 1.02 KB
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
const express = require('express');
const app = express();
const path = require('path');
const bodyParser = require('body-parser')
const morgan = require( 'morgan' );
app.use('/assets', express.static(path.join(__dirname, 'assets')));
app.use('/dist', express.static(path.join(__dirname, 'dist')));
app.use('/public', express.static(path.join(__dirname, '/public')));
app.use('/vendor/bootstrap', express.static(path.join(__dirname, 'node_modules/bootstrap')));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(morgan('dev'));
app.use('/api', require('./routes'));
app.get('/*', (req, res, next)=> res.sendFile(path.join(__dirname, 'public/index.html')));
// ......error middleware not wired to anything.
// ......error status sent back to index.html
app.use((req, res, next) => {
const error = new Error('page not found');
error.status = 404;
next(error);
});
app.use((err, req, res, next) => {
console.log(err)
res.status(err.status || 500).send(err.message);
});
module.exports = app;