forked from tmushayahama/panther-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (33 loc) · 963 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
37
38
39
40
41
42
43
'use strict';
var SwaggerExpress = require('swagger-express-mw');
var cors = require('cors');
var app = require('express')();
module.exports = app; // for testing
var config = {
appRoot: __dirname // required config
};
var corsOptions = {
credentials: true,
origin: function (origin, callback) {
if (origin === undefined) {
callback(null, false);
} else {
var match = origin.match("^(.*)?.http://127.0.0.1(\:[0-9]+)?");
var allowed = (match !== null && match.length > 0);
callback(null, allowed);
}
}
};
app.use(cors(corsOptions));
SwaggerExpress.create(config, function (err, swaggerExpress) {
if (err) {
throw err;
}
// install middleware
swaggerExpress.register(app);
var port = process.env.PORT || 10011;
app.listen(port);
if (swaggerExpress.runner.swagger.paths['/hello']) {
console.log('Then, open a second command line and launch the editor with: "swagger project" edit');
}
});