2016-07-27 72 views
1

我使用swagger-express-mw NPM包創建REST服務,當我用「swagger project start」運行項目,然後通過HTTP發佈API時,我怎麼能改用HTTPS。HTTPS與NodeJS swagger-express-mw npm包

我一直在使用如下香草NPM包使用HTTPS:

var fs = require('fs'); 
var https = require('https'); 
var app = require('express')(); 
var options = { 
    key : fs.readFileSync('my.private.key'), 
    cert : fs.readFileSync('my.certificate.cer') 
}; 

app.get('/', function (req, res) { 
    res.send('Yuhooo! Response over HTTPS!!! '); 
}); 

https.createServer(options, app).listen(8443, function() { 
    console.log('Server started @ 8443!'); 
}); 

但我不知道如何實現與招搖快車兆瓦是相同的,下面是從我的app.js的代碼片段,其啓動聽衆。沒有得到任何選項來使用HTTPS這裏

SwaggerExpress.create(configuration, function(err, swaggerExpress) { 
    if (err) { throw err; } 
    // install middleware 
    swaggerExpress.register(app); 
    var port = config.get('server.port') || process.env.PORT || 8080; 
    app.listen(port); 
console.log('Server started at port %d', port); 
}); 

var swaggerDoc = jsYaml.load(fs.readFileSync('./api/swagger/swagger.yaml')); 
// Initialize the Swagger middleware for the api doc purpose 
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) { 
    // Serve the Swagger documents and Swagger UI 
    app.use(middleware.swaggerUi()); 
}); 

回答

3

app.listen的協議僅僅是一個快捷方式,你可以使用

SwaggerExpress.create(configuration, function(err, swaggerExpress) { 
    if (err) { throw err; } 
    // install middleware 
    swaggerExpress.register(app); 
    var port = process.env.PORT || 443; 
    https.createServer(options, app).listen(port, function() { 
     console.log('Server started @ %s!', port); 
    }); 
}); 
0

使用揚鞭2.0規範與中間件你招搖的配置文件可以設置爲僅接受某些方案:

# Schemes is statically set here but will be overridden in app.js with 
swagger object 
schemes: 
    - https 

您可以查看說明書,去固定字段:http://swagger.io/specification/