-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (33 loc) · 872 Bytes
/
app.js
File metadata and controls
41 lines (33 loc) · 872 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
35
36
37
38
39
40
41
import express from 'express';
import cors from 'cors';
import morgan from 'morgan';
import methodOverride from 'method-override';
import routes from './routes';
const isProduction = process.env.NODE_ENV === 'production';
const app = express();
app.use(cors());
app.use(morgan('dev'));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(methodOverride('_method'));
app.use(routes);
app.use('*', (req, res) => {
res.status(404).json({ status: 404, message: 'Page not found' });
});
if (!isProduction) {
// / catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
}
app.use((err, req, res) => {
res.status(err.status || 500).json({
errors: {
message: err.message,
error: err,
},
});
});
export default app;