-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (29 loc) · 826 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
'use strict';
let SwaggerExpress = require('swagger-express-mw');
let app = require('express')();
let jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
let conf = require('config');
let models = require('./sequelize/models');
module.exports = app; // for testing
let config = {
appRoot: __dirname, // required config
swaggerSecurityHandlers: {
Bearer: function (req, authOrSecDef, token, cb) {
jwt.verify(token, conf.get('jwt.secret'), function(err, decoded) {
if (err) {
cb(new Error('Access Denied!'));
} else {
req.jwt = decoded;
cb();
}
});
}
}
};
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }
// install middleware
swaggerExpress.register(app);
let port = process.env.PORT || 10010;
app.listen(port);
});