a very dirty workaround is to temporarily change localhost to something like 192.168.1.100 - but that's far from perfect.
Feb 3, 2021
2
Level 14
How to get rid of the hardcoded "localhost" in .env files?
I have 2 .env files (one for Vue and one for Laravel). Both of them have localhost hard coded inside of them. That means that I can't access my application from another computer on my network.
For example if I go to my other PC and access my site at http://192.168.1.100:47344 then it won't work because it is hardcoded to localhost.
But I can't write javascript or PHP inside .env files to change localhost to something like window.location.host and for PHP $_SERVER['SERVER_ADDR']. I can't find the solultion..
My Vue .env
VITE_SERVER_URL=http://localhost:41166
VITE_APP_ENV=dev
And my Laravel .env
APP_ENV=local
APP_CLIENT_URL=http://localhost:47344
APP_URL=http://localhost:41166
Please or to participate in this conversation.