forked from jackmeagher/iqms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
67 lines (53 loc) · 1.73 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"use strict";
var express = require('express');
var app = express();
var Resource = require('./lib/Resource');
var models = require('./models');
var bodyParser = require('body-parser');
var jwt = require('jsonwebtoken');
const secret = 'tg6bhr5dxddrtcx';
app.use(bodyParser.json());
app.use((req, res, next) => {
var token = req.get('token');
if (token) {
jwt.verify(token, secret, (err, decoded) => {
if (err) {
res.status(403).json({
'success': false,
'msg': "Invalid token (perhaps expired).",
'error' : err
});
} else {
req.user = decoded.user;
next();
}
});
} else {
req.auth = false;
req.user = undefined;
next();
}
});
var answer_routes = require('./routes/answer');
var role_routes = require('./routes/role');
var interview_routes = require('./routes/interview');
var question_routes = require('./routes/question');
var user_routes = require('./routes/user');
var tag_routes = require('./routes/tag');
var position_routes = require('./routes/position');
question_routes.register(app,'');
interview_routes.register(app,'');
answer_routes.register(app,'');
user_routes.register(app,'');
role_routes.register(app,'');
tag_routes.register(app,'');
position_routes.register(app,'');
app.use('/static', express.static('../static'));
// middleware to add headers for cross origin requests
app.all('/*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type,X-Requested-With');
next();
});
//var testq = require('./testData');
module.exports = app;