-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
43 lines (32 loc) · 1.03 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
var express = require('express');
var cors = require('cors');
var swaggerTools = require('swagger-tools');
var errorhandler = require('errorhandler');
var nconf = require('./nconf');
var swaggerObject = require('./api/swagger');
var security = require('./utils/security');
var param = require('./utils/param');
swaggerTools.initializeMiddleware(swaggerObject, function(middleware) {
var securityOptions = {
tokenName: nconf.get('security:tokenName'),
id: nconf.get('feature:id'),
secret: nconf.get('feature:secret')
};
var routerOptions = {
controllers: __dirname + '/' + nconf.get('swagger:controllers')
};
var corsOptions = {
exposedHeaders: ['X-Total-Count']
};
var app = express();
app.use(cors(corsOptions));
app.use(middleware.swaggerUi());
app.use(security(securityOptions));
app.use(param());
app.use(middleware.swaggerMetadata());
app.use(middleware.swaggerRouter(routerOptions));
app.use(errorhandler());
app.listen(nconf.get('port'), function() {
console.log('start up');
});
});