This repository was archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (36 loc) · 1.23 KB
/
app.js
File metadata and controls
49 lines (36 loc) · 1.23 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
'use strict';
var SwaggerExpress = require('swagger-express-mw');
var express = require('express');
var app = express();
var config = require('./config.js.template');
module.exports = app; // for testing
//Allow access to docs
app.use(express.static('public'));
var swaggerConfig = {
appRoot: __dirname, // required config
swaggerFile: __dirname + '/api/swagger/swagger.json',
swaggerSecurityHandlers: {'DefaultSecurity': (req, authOrSecDef, scopesOrApiKey, cb) => {
if (scopesOrApiKey === config.api.apiKey) {
cb();
} else {
cb(new Error('Wrong or Missing API key'));
}
}},
};
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
require('./database.js').connect(null,function (context) {
SwaggerExpress.create(swaggerConfig, function (err, swaggerExpress) {
if (err) {
throw err;
}
// install middleware
swaggerExpress.register(app);
var port = process.env.PORT || 10010;
app.listen(port);
console.log('Server running at http://127.0.0.1:' + port);
});
});