-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (34 loc) · 904 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
35
36
37
38
39
40
41
42
43
44
require('dotenv').config();
const express = require('express');
const { sequelize } = require('./models');
const index = require('./routers');
const app = express();
app.use(express.json())
app.use(express.urlencoded({ extended: true })); //enables express to pass url encoded form format
app.disable("x-powered-by");
app.use('/api/v1/', index);
// Handle cases where invalid JSON data is passed
app.use((err, req, res, next) => {
if (err.type === 'entity.parse.failed') {
res.json({
status: 'error',
message: 'invalid JSON passed',
data: null,
});
} else {
next();
}
});
app.get('/',(req,res)=>{
return res.status(200).json({
message: 'stack_lite API',
})
})
//catches all unassigned routes
app.all('*', (req, res) => {
res.status(404).json({
status: 'error',
message: 'that route does not exist',
});
});
module.exports = app;