-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (38 loc) · 1.01 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Author: Greg Brooks
See README.md for more info
*/
const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` })
const api = require('./api/v1');
const app = express();
//middleware
app.use(cors());
app.set('trust proxy', 1);
app.use(express.json());
app.use(morgan('dev'));
// default welcome message when presented with simple GET from end point /api/v1/logger
app.get('/', (req, res) => {
res.json({
message: 'Welcome to NodeJsAlive Backend',
lastest_version: 'v1.0'
});
});
app.use('/api/v1', api);
// ERROR 404 response if route not found
app.use((req, res, next) => {
const error = new Error('Route Not Found');
error.status = 404;
next(error);
});
// Send response to client with default server fault error of 500 if unknown
app.use((error, req, res, next) => {
res.status(error.status || 5000);
res.json({
error:{
message: error.message
}
});
});
module.exports = app;