Reputation: 330
I am using swagger-express-mw NPM package for creating REST services, when I run the project with "swagger project start" then it publishes the APIs over HTTP, how can I use HTTPS instead.
I have used HTTPS using vanilla npm packages as below:
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!');
});
But I am not sure how to achieve the same with swagger-express-mw, Below is the code snippet from my app.js which starts the listener. Not getting any option to use HTTPS as the protocol here
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());
});
Upvotes: 2
Views: 3222
Reputation: 1476
Using Swagger 2.0 spec with middleware your swagger configuration file can be set to only accept certain schemes:
# Schemes is statically set here but will be overridden in app.js with
swagger object
schemes:
- https
You can review the specification and go to Fixed Fields: http://swagger.io/specification/
Upvotes: 0
Reputation: 9368
app.listen
is simply a shortcut you can use
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);
});
});
Upvotes: 3