-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (29 loc) · 964 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
const express = require('express');
const user = require('./models/user');
const { healthz } = require('./routes/health');
const { createUser } = require('./routes/createUser');
const {userSelf} = require('./routes/userSelf');
const { sequelize } = require('./db');
const logger = require('./logger');
const { userVerify } = require('./routes/userVerify');
sequelize.sync().then((result)=>{
// logger.info(result);
}).catch((err)=>{
logger.error(err);
});
const app = express();
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use((err,req,res,next)=>{
if(err instanceof SyntaxError && err.status===400 && 'body' in err){
return res.setHeader("Cache-Control", "no-cache").status(400).json();
}
})
app.use(healthz);
app.use('/v2',createUser);
app.use('/v2/user',userVerify);
app.use('/v2/user',userSelf);
app.all((req,res,next)=>{
res.setHeader("Cache-Control", "no-cache").status(404).json().end();
});
module.exports=app;