This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi.
I have a pretty simple express app that I was building locally.
I took this express app and deployed it to render. The front end javascript has an axios call, I am surprised that it works / I would like to understand why / how it works.
express was running locally, and the client side js has a call
//axios.get("http://localhost:3000/results")
axios.get(axiosURL "/results")
This was originally hard coded, but then replaced by a matching environment variable on my local deploy.
What I had expected was that if I deploy to render, the client side javascript will not work {since it will query localhost/results}. I don't have a listener up on my mac while testing render's deploy. Somehow, this call still worked.
I had been planning to pass environment variable to the client side script. Changing these env variables once I get the url for the render deploy. I am confused why this worked, on render, when the above url calling for localhost {since... my current localhost does listen on 3000}
Does render somehow, see the variables for localhost and replace it with its own hostname? Inspecting chrome dev tools I see that axios did infact call :https://imresultscraping.onrender.com/results - however I absolutely did not expect this. Its as if render took the client side js code, looked for localhost - and replaced localhost with the resolved app url post deploy.
This is very cool... however un-expected. Are there any other nifty things render might be doing / does this behavior cause un-intended consequences elsewhere?
Thanks!
Subreddit
Post Details
- Posted
- 4 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/AskProgramm...