I have a website which is completely client-side. When it is in a testing environment, I use localhost for all links to other services: databases, report builders, etc.
When the website is deployed to apache2, for to go live, I have to manually change those link to the IP address of the server.
Is there any way in code to avoid doing this? Or, is the only way to automatically change them (grunt for example) during the deployment phase?
You could check the window.location object and put some conditional logic around the hostname, eg if (window.location.hostname == 'localhost') {}
.
Although mixing environment specific / test-time code is typically a smell. Your hunch about this being a build/deploy time activity is probably the right way to go. The gulp-inject plugin is worth considering.
i was about to write how to do it, but this website says it all: http://subinsb.com/linux-apache-localhost
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.