nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.89k stars 7.56k forks source link

WebSocket Gateway - Secure websockets #384

Closed popovicidinu closed 6 years ago

popovicidinu commented 6 years ago

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I'm using NestJS for a project we're launching, and I've recently introduced a WebSocket Gateway for a functionality of the project. Everything works as expected, but in "production", I'm running the app as an HTTPS server. It seems that the websocket isn't working with the "wss" protocol. I'm not entirely sure if it's an issue with my code or the websocket gateway and I couldn't find any HTTPS examples around the documentation.

The socket seems to work, but the response I'm getting back when trying to connect says the response is insecure. (See below).


Failed: Error in connection establishment: net::ERR_INSECURE_RESPONSE

Thanks.

Environment


Nest version: 4.5.9


The code that is relevant to the scenario I'm describing: 

 import * as https from 'https';

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

app.then(instance => {
    instance.init();

    const httpsInstance = https.createServer(options, expressInstance).listen(process.env.PORT);
});
kamilmysliwiec commented 6 years ago

Thanks for reporting, will verify :)

kamilmysliwiec commented 6 years ago

Since v4.6.2 there's a simpler way of dealing with HTTPS:

const app = await NestFactory.create(ApplicationModule, {
    httpsOptions: options,
});
await app.listen(3000);

With this approach, Gateways will work fine. 🙂

BorntraegerMarc commented 6 years ago

@kamilmysliwiec maybe we want to add this new way of creating a HTTPS server also to the docs? 😄

popovicidinu commented 6 years ago

@kamilmysliwiec Thanks a lot for showing how to include HTTPS options.

@BorntraegerMarc Indeed, I think it would be a good idea that this would be added to the docs in the near future.

Awesome work on this project. I'm using it in production for a medium-sized project and it works flawlessly so far.

lock[bot] commented 4 years ago

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.