-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
50 lines (41 loc) · 1.14 KB
/
Copy pathapp.js
File metadata and controls
50 lines (41 loc) · 1.14 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express = require('express');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const cors = require('cors')
const helper=require('./helper')
const index = require('./routes/index');
const app = express();
app.use(logger('dev'));
app.use(cors())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}))
app.use(cookieParser());
app.set('port', process.env.PORT || 4444);
app.use(async (req, res, next) =>{
try {
console.log(req.url)
if(req.url==='/user/login'){
return next()
}
const verifyData =await helper.jwtTokenVerify(req, res, next )
if(verifyData){
return next()
} else {
return res.json({ status: -1, msg: "Auth failed" });
}
} catch (err) {
return res.json({ status: -1, msg: "Auth failed" });
}
});
app.use('/', index);
// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
app.listen(app.get('port'), async(err,res) => {
console.log("server is running on 4444");
});
module.exports = app;