Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple simultaneous servers (e.g. HTTP and HTTPS) #20

Closed
Jephery opened this issue May 3, 2017 · 2 comments
Closed

Support for multiple simultaneous servers (e.g. HTTP and HTTPS) #20

Jephery opened this issue May 3, 2017 · 2 comments

Comments

@Jephery
Copy link

Jephery commented May 3, 2017

The current implementation of NestApplication.listen() does not support easily adding multiple Server backends, since it directly calls .listen() on the Express Application (which only creates an HTTP server).

At the very least, it would be helpful to add a public method on NestApplication that calls the setup functions (setupMiddleswares, setupRoutes, etc.) without calling express.listen().

For anyone else having this issue, a workaround is below:

const expressInstance = express();

const app = NestFactory.create(ApplicationModule, expressInstance);

app.listen(80, () => {
    console.log("HTTP server listening on port 80");
});

let httpsOptions = {
    key: fs.readFileSync("./secrets/private-key.pem"),
    cert: fs.readFileSync("./secrets/public-certificate.pem")
};

const httpsServer = https.createServer(httpsOptions);
httpsServer.addListener("request", expressInstance);
httpsServer.listen(443, () => {
    console.log("HTTPS server listening on port 443");
});
kamilmysliwiec pushed a commit that referenced this issue May 5, 2017
kamilmysliwiec added a commit that referenced this issue May 5, 2017
@kamilmysliwiec kamilmysliwiec self-assigned this May 9, 2017
kamilmysliwiec pushed a commit that referenced this issue May 23, 2017
…onfiguration class, multiple servers, global route prefix (#70, #20, #40)
@kamilmysliwiec
Copy link
Member

Hi @Jephery,
Since version 2.1.0 it is possible to directly call init() method on NestApplication instance. However, listen() method is backwards compatible. Example:

let httpsOptions = {
    key: fs.readFileSync("./secrets/private-key.pem"),
    cert: fs.readFileSync("./secrets/public-certificate.pem")
};

const server = express();
const app = NestFactory.create(ApplicationModule, server);
app.init();

http.createServer(server).listen(3000);
https.createServer(httpsOptions, server).listen(443);

@lock
Copy link

lock bot commented Sep 25, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants