我使用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());
});