4 months ago
I've a Nest.js app that is working fine on local and Docker, but when I deploy it to Railway, it gives me an error.
I've tried every suggestion from AI to resolve it, but it's not working
I've tried using the internal address, and right now I've set public URL of the backend to connect to it, but still I'm seeing this error
WebSocket connection to 'wss://{backend-url}.up.railway.app/socket.io/?EIO=4&transport=websocket'
the error redirects me to this part:
class X extends K { createSocket(t, e, s) { return $ ? new W(t,e,s) : e ? new W(t,e) : new W(t) } doWrite(t, e) { this.ws.send(e) } }
Can you help me solve it?
5 Replies
Hi @Aref , it may be related to CORS. Can you try to add something like
@WebSocketGateway({
cors: {
origin: '{backend-url}.up.railway.app'
},
})I have origin in env file
FRONTEND_URL="https://{frontend}.up.railway.app"
do i need to backend here as well?
`const websocketOrigins = getAllowedOrigins();
const resolvedOrigins =
websocketOrigins.length > 0 ? websocketOrigins : ['http://localhost:3000'];
@WebSocketGateway({
cors: {
origin: resolvedOrigins,
credentials: true,
},
namespace: '/',
transports: ['websocket', 'polling'],
})
@UseGuards(WsJwtGuard)
export class EventsGateway
implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect
{`
Can you try origin: "*" just to see if the issue is coming from there ?
What do you see in your browser network tab with Socket filter ?

