Reverse proxy returning 502, but the underlying app is running
Trying to set up a simple proxy to handle CORS, but the proxy can't reach the application. It was working moments ago (without the CORS config) but I can't pinpoint what changed
Solution:Jump to solution
we aren't going to use a proxy, there's no reason to use a proxy just to set cors headers
78 Replies
Project ID:
9a8ccdaa-0d00-40e4-823c-5199e84248cf
9a8ccdaa-0d00-40e4-823c-5199e84248cf
what kind of app are you trying to add cors headers to
a Node.js app
having issues with the native way
issues = doesn't seem to work :p
well let's try to solve the actual underlying problem and not add more problems on top
k
so we are throwing out the entire proxy thing, there shouldn't be anything wrong with setting headers from your app itself
so more specifically what kind of node app is this
so, here's the proxied link:
https://bot-server-proxy.karensama.com/link
and here the app with it's own domain:
https://bot-server.karensama.com/link
it should say Cannot GET
cuz it's a POST route, butyou can see one is visible and the other blanks
Solution
we aren't going to use a proxy, there's no reason to use a proxy just to set cors headers
ye, I'm just on a deadline and trying everything to get this out man
ok, removing the proxy
you have access to the node apps code right?
yep
^
okay and show me some errors you get on the frontend that relate to cors?
rn it's failing because of the 502 on the proxy
I'm redeploying without the proxy, sec
brah
it's working now
you must have a magic wand or something
š
see, no need to over complicate things
when I sent you this, I realised the origins didn't have the protocol
now the app doesn't work, but that's on me xD
thanks again sir!
no problem! š
best support ever ā¤ļø
thank you ā¤ļø
if you're still here, I have another server with the same codebase running
node telegram.js
which is a telegram bot thingy
the app we were talking about connets to that through websockets
like so:
this is the value of the env var: ws://karensama-tg-socket.railway.internal/
you need to use a port in that url
the thing is the domain always redirects to the $PORT, no?
I tried with he port too, no bueno
nope, don't treat the internal domains like the public domains, you can think of like your local network but instead of IP addresses it's a nice domain name, you will always need to specify a port
perhaps I'm setting the wrong port? I have $PORT set to 8805
but not sure that's what gets exposed
your app would also need to listen on
::
to be accessable over the ipv6 only private networkI've set up a subdomain now
it's a private network, everything is exposed, there's no proxy and no firewall
ws://socket.karensama.com:8805/
but I'm pretty sure 8805 is not the port mapped to the service's 8805^
still applies using the public domain?
you are using the private domain for this?
I was, but I'm trying to use all the options
saw on the internet somewhere that internal domains are unstable for websockets and thought it might be related
nope not at all, where did you read that?
Railway | Help Center
WebSocket Connections Disconnecting ā Railway | Help Center
Steps to take to make sure that WebSockets are behaving as expected on the platform.
ok, I have it set this way now: ws://socket.karensama.com:8805/
8805 is the $PORT for the tg bot app, so it's running on that port
that doesn't say anything about internal domains?
misread perhaps, not internal, but the wildcard domains
what service is starting the websocket server
tg-websocket
what host is it listening on
::
can you show me how you configured that
server.listen(process.env.WEBSOCKET_PORT_TELEGRAM, '::', () => console.log(
Websocket open on port ${process.env.WEBSOCKET_PORT_TELEGRAM}));
I can change that port to something else if needed
this is an old app that was in a single repo and I'm breaking it down into isolated thingsit is in the same project right?
yep
and what error are you getting trying to connect to it
I don't see I can see those logs anywhere
the same way you showed me these logs
that log never shows up in the platform's logs
are you logging to stdout/stderr?
good question
how is bot-server being built? nixpacks? dockerfile?
the default railway offer, it doesn't actually need to build other than npm install
then it runs as
node server.js
and node telegram.js
respectivelyI can see this on the logs, after making a request to the server, which would use the websocket
but that's a caught exception from here
I'll remove the handler to see the error
no lol, just log the error too
I have no idea where the error is to log it :p
so I'll jsut let it explode
well that's one way to do it
show me the wsTelegram code
what if I told you that removing those lines, it works?
you gotta be kidding me javascript
the error handler was erroring š¤¦āāļø
sounds flakey, do a few more redeploys to see if it's stable
ye, I'll definitely do that
at what point in your apps lifecycle do you make this connection to the websocket server
at initialization
the very first lines after the imports:
there is around 2 seconds when your app starts where the dns resolver for the private network hasn't initialised yet, add a sleep for 3 seconds before attempting the websocket connection
hmmmmm that's interesting
but definitely use a health check so that railway knows when your app starts
yeah, Railway offers all the tools for me to avoid that happening
but I should have deployed this yesterday already and spent a;lll day fiddling in AWS
well you made the right choice coming to railway
tell me about it!
devops devs dont work on Fridays
š¤£
if I was to ask a devops to set all this up in aws, would get a week timeline probably
this is the correct place to check for app logs, right?
yes it is, if you are logging to stdout / stderr without buffering it will show up there