How to initialize HTTPS server? #1243
Answered
by
attilaorosz
TokugawaTakeshi
asked this question in
Q&A
-
Unfortunately, I have not found the HTTPS examples in README.md of the routing-controllers package. Below example starts HTTP server, not HTTPS, is not it? import { createExpressServer } from 'routing-controllers';
import { UserController } from './UserController';
// creates express app, registers all controller routes and returns you express app instance
const app = createExpressServer({
controllers: [UserController], // we specify controllers we want to use
});
// run express application on port 3000
app.listen(3000); AFAIK, with plain Express, the HTTPS server must be run via passing of the express application instance as the parameter of var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();
// your express configuration here
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(8080);
httpsServer.listen(8443); Will it work with "routing-controllers"? I hope there is the way to use the HTTPS because HTTPS is de-facto required today. |
Beta Was this translation helpful? Give feedback.
Answered by
attilaorosz
Oct 1, 2023
Replies: 1 comment 1 reply
-
You can use |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
TokugawaTakeshi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
useExpressServer
instead and pass in your express instance and start the https server as in your example.