However, when I visit my customized domain name test.console.snarkify.io which has a CNAME record pointing to test-aws–snarkify-cloud.netlify.app, the backend API it was trying to access become our production configuration (api.snarkify.io). This is totally beyond my comprehension, how is it even possible that the same server will pick up different env vars when accessed from different domain names?
Can someone help me figure out how this could be fixed?
I’d imagine that test.console.snarkify.io for whatever reason isn’t actually the same thing as https://test-aws--snarkify-cloud.netlify.app
However since you’re using next.js, and if SSR could be involved, as far as I’m concerned “almost anything might be happening”. Checking the source of the site when accessed by the two URLs, (and hoping that they’re at least somewhat static or representative of a unique build), it shows different build id’s and hashes on the various files.
I just verified that the build id of test.console.snarkify.io is exactly the same as our production version.
I’m not a FE so I want to make sure I understand your points correctly. Does it mean that next.js is doing some magic that results in the difference? And it potentially leads me to the production build?
By FE, I mean frontend engineer, sorry for using less well known abbreviations.
After digging more into the configurations, I think I found the root cause. The domain name test.console.snarkify.io has been added to the Production domains in the domain name configuration tab. After removing it I think it’s now resolved to the right service, only with some certificate issue to fix. But that’s another story.