Enable local network sharing#1284
Conversation
By removing te IP address from the HTTP_HOST we enable a rudimentary version of local network sharing. Co-authored-by: Mickael Urrutia <mickael.urrutia@utc.fr>
|
Also, could anyone confirm or deny if this breaks Laravel Valets' wildcard DNS support? I don't use |
|
I'm good with this modification, but I'll need someone who uses nip.io to test it out for me first. Put out a request: https://twitter.com/stauffermatt/status/1598332500056621062 |
|
I tested it on my setup and it worked, but there is a problem with Drivers. $_SERVER['SERVER_ADDR'] = '127.0.0.1';that overrides server address, making a redirect to $serverAddr = $_SERVER['SERVER_ADDR'];
// condition when to override the server address if necessary
if (!$serverAddr || $serverAddr == 'localhost') {
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
}same goes for every driver that do this. I can make a PR, but I would need to know when to enable this override 😄 |
|
@F0rsaken Unfortunately I don't know yet whether your code there would or wouldn't be enough... I'm guessing it would be? I'll test it out and see if I can figure out. |
|
OK. I made a modification similar to yours @F0rsaken, but I didn't worry about the In theory that means this PR should work. I'll test it out now or shortly. |
|
Well.. this isn't perfect, but it at least is a start, with a bit of a potential fix, and it makes the docs at least a bit less inaccurate. lol. I just ran it and it worked, but with the same issues mentioned w/r/t the assets. Thanks @thinkverse! |
This PR enables a rudimentary version of local network sharing with the fix mentioned in (#440 (comment)). This pull request was suggested in (laravel/docs#8267) by @driesvints.
I've tested the fix locally and it does enable local network sharing, though it's rudimentary at best since assets don't load properly given the URL doesn't match.
For example, if I have
http://laravel.testand access is via local network sharinghttp://192.168.1.111/laravel.test, the site does load. But the asset URLs will usehttp://laravel.testand thus not load. I'm not sure if that is due to the@vitedirective or something else. The same thing happens with theassethelper, which might be because of theAPP_URL.I did manage to get the CSS, JavaScript, and HMR working with Vite by starting the Vite server using the local IP address passed in as the host.
Since Vite adds the IP address in the
scriptandlinkfiles, the IP address used for the host must be an address that can be accessed by all devices over the network, The safest route is to use the same IP address of the device you're trying to expose.Not sure how to go about fixing the issue of built assets not loading due to the URL not matching though. 🤷♂️