I have an angular SPA application running on port 4200 http://localhost:4200
. I’m forwarding my NestJS api using proxy.conf.js
:
'/api': {
secure: false,
target: `http://localhost:3000`,
headers: { 'X-Forwarded-Host': process.env.X_Forwarded_Host },
ws: true,
},
};
All basic HTTP routes are working. For example http://localhost:3000/health
and http://localhost:4200/api/health
are working correctly.
But for WS, http://localhost:3000/socket.io
is working, but http://localhost:4200/api/socket.io
is not. I’m having a timeout without any error (no CORS errors for example)
I am missing something ? Here is my WebsocketGateway declaration in NestJS:
@WebSocketGateway({
cors: {
origin: [process.env.PWA_URL],
credentials: true,
},
})
PWA_URL
is http://localhost:4200
.
I need to acces my Websocket app using http://localhost:4200
because my production environment only expose the public facing PWA application. My API is only accessible from this port-forwarding.
Thanks a lot for your help !