-
Notifications
You must be signed in to change notification settings - Fork 718
Fallback Site Path #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback Site Path #439
Conversation
…" path set, Valet's server script uses it for uncaught urls).
|
This is an interesting PR. |
|
@joshmanders Cheers! The particular use case I wrote it for is as follows… I'm creating a web app for a trade show, where there'll be a web server and a bunch of peripheral devices (phones, tablets, etc) on the same LAN connecting to that server via their web browsers. With this PR I simply run As an aside, there are obviously many ways to determine your LAN IP, but the following bash alias (throw it in your _ip() {
ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'
}
alias ip=_ip |
|
This works great for my use case (#440). The only problem I have is getting an SSL certificate to work for my Mac's LAN IP address. Any ideas on what I can do? |
|
Hi @mikemand! My SSL/network knowledge is limited, but as an avid tinkerer I just had to dive in for you. I started by hacking the /**
* Secure the given domain with a trusted TLS certificate.
*/
$app->command('secure [-i|--ignoreTLD] [domain]', function ($ignoreTLD, $domain = null) {
$url = ($domain ?: Site::host(getcwd()))
.($ignoreTLD ? '' : '.'.Configuration::read()['domain']);
Site::secure($url);
PhpFpm::restart();
Nginx::restart();
info('The ['.$url.'] site has been secured with a fresh TLS certificate.');
})->descriptions('Secure the given domain… etc');
/**
* Stop serving the given domain over HTTPS and remove the trusted TLS certificate.
*/
$app->command('unsecure [-i|--ignoreTLD] [domain]', function ($ignoreTLD, $domain = null) {
$url = ($domain ?: Site::host(getcwd()))
.($ignoreTLD ? '' : '.'.Configuration::read()['domain']);
Site::unsecure($url);
PhpFpm::restart();
Nginx::restart();
info('The ['.$url.'] site will now serve traffic over HTTP.');
})->descriptions('Stop serving the given domain… etc');…and even though the appropriate certificates got created… …the browser still errored: A little Googling revealed it doesn't sound like you can achieve what you're after… https://community.letsencrypt.org/t/certificates-for-hosts-on-private-networks/174 …but I ain't no expert, so, maybe? 🤷♂️ |
|
You can't create an ssl cert for ips. |
|
@joshmanders Gotcha. Thanks for clarifying!
|
|
Thank you guys for the research and help. I'll see if I can create a subdomain and get an SSL for that, then just point the A record at my LAN IP. |
|
For HTTPS, no matter how you slice it, Valet will still issue a self-signed certificate ... and therefore any other device that connects will need to click to Accept / Trust that certificate when visiting the site for the first time. To get around that, you'd need to register a proper domain (and point the A record to your local IP, as you said), get an SSL cert for it, and then manually configure your local nginx configs to use that specific SSL cert. And then NOT use Valet's |
|
While the following doesn't fix the "self-signed cert" "issue", you could leverage http://xip.io for minimizing some DNS complexity:
(Still have to do HTTPS separately) Alternatively, you could sign up for a Free DNS provider and pick a vanity domain (like There are other variations as well. Just mentioning these 2 for the benefit of those who didn't know about the .xip.io option, or about 3rd-party free dns services. |
|
@drbyte: You are amazing. I did not know about xip.io before now, and it has saved my sanity. Here's what I did, for anyone else that wants to do so as well:
At this point, I had to navigate to My application is a very simple Lumen application with two endpoints: I should note that this is all from a completely fresh install of Valet. I don't have any other applications running on it and for my current use case I won't have to...I'm just using it has a bridge between my SSL-secured website and a Zebra GX420d printer that doesn't have SSL (stupid Zebra -.-). |
|
@mikemand Just followed your instructions and I can confirm that by doing so, https via |
|
I'm not sure if this will work, but I'm going to try anyway: Closes #440 |
|
I tend to agree. It serves a slightly different purpose than I've wrestled with whether the |
|
the main purpose here is to share for dev purpose, not share for send links to clients. |
|
Any updates on when this might be merged? I would really like this to be "official" so I can use it in my project. |
|
(Until it's merged, I'm just using it directly in my |
|
I've been using this with no problems or difficulties since September. 👍 to merge IMO. |
|
I've also been using it since submission (LAN kiosks) and have had no issue either. 🤓👍 |
|
Is this basically to replace the 404 page? |
Yes and no. In short, with a
Longer explanation: its purpose in the author's original context was to set up the machine to respond to In the author's example, it was to allow the server to respond to "kiosk" devices within a local network, in this case at a trade show. |
|
Oh that makes sense, I actually used Valet for something like that in the past and it just happened to be the quickest way to set up a PHP web server. Cool. |
|
I'd like to merge this but I don't like the "fallback" terminology. What do you think about calling it the "default" site rather than the fallback site? The hard part is naming the "remove default" command :/ |
|
Perhaps rename |
…or any combination of the above? |
|
What about making it a flag of the |
I like it. And |
@drbyte So to remove the default/fallback site path, you'd have to navigate to the default/fallback site path before running How about simply providing a FYI the term fallback was chosen to mirror existing terminology littered throughout the framework. I'm not precious and will happily resubmit as Thoughts? |
|
@furey As far as I know, |
|
So to clarify (and before making changes to the PR), the proposed API would be… Set Fallback Site PathWhen the working directory is the intended fallback site path:
Remove Fallback Site PathWhen the working directory is the fallback site path:
When the working directory is not the fallback site path, but the fallback link name is specified:
When the working directory is not the fallback site path, and no link name is specified:
|
|
I like it. |
|
Hi @drbyte, My thinking supplement's the existing To elaborate…
Hope that makes sense. If not, perhaps piggybacking Naming, right? 🤷♂️ |
|
Yup. Naming is tough. I like the end-user simplicity of simply adding I'm still undecided whether I'm leaning more and more to just: Also it looks like after the necessary coding changes, the word 'fallback' can be safely changed to 'default' in all cases, and still retain the intended meaning. |
|
I don't love any of the API suggestions so far, so here's what I think we should do: Let's make this a sort of "advanced" feature that you setup directly in your config file, at least for now. We'd keep all the logic this PR adds around checking if a default site is set and serving that if needed, but remove the actual CLI commands to set it; instead recommending that people just change that path in their This way we get the feature in now for folks who need it, but avoid committing to an API we may later regret. |
|
Ooooo! A secret undocumented advanced feature! Easter-Eggs, just in time for easter! |
|
I like that idea @adamwathan |
…g that if needed, but removed the actual CLI commands to set it (recommending people add/change their "default" path in their ~/.valet/config.json file manually).
|
Hi @adamwathan, I've updated the PR as per your instructions:
Cheers! 🤓🤞 |
|
Finally, yay! Are there any other steps we need to take to get the default site running (other than editing the config file)? Restart valet/dnsmasq/php/etc.? Should we have this site already linked? Edit: I'm just trying to cover all the bases. :) Thank you @furey and @adamwathan! (And @drbyte too!) |
|
@mikemand Nothing special required (no restarts, no linking needed), other than adding the path to After doing that, when visiting any IP linked to your computer, whether localhost |
Implementation from PR laravel#439
|
Sorry guys, I moved to dev-master (composer global require laravel/valet=dev-master), I have created a new .valet directory (there was not there at all) under my home directory and created a new config.json file in it looking at the adamwathan image. If I visit 127.0.0.1 the default site does not shows up...I got a simple "404 - Not Found" what am I missing? |
|
@alextime A long time ago the |
Many thanks, I didn't know it. Now it works even if electron does not to debug Vue using mobile devices... |
|
I just tried this, connecting from my phone, which is on the same LAN. I type the Mac's IP, and then the phone browser immediately redirects to the Valet domain e.g. "magento.test", this hostname however does'nt exist on the phone, so the page is not loaded. Am I missing something here? |
|
@elburro1887 what is doing the redirecting? I think that might be magento that is doing that, not valet. |
|
@eberkund Yes, that could be the reason, I'll have a look, thanks! |
|
I'm on valet 2.8.1, the default directive on config.json does work well, because if I visit localhost or 127.0.0.1 I actually see the default site. But if I visit my lan ip I got a ERR_CONNECTION_REFUSED error, even if I visit my ip from my very same Mac. I'm on Catalina 10.15.3 and I thought of some firewall issue, but firewall is not active and I do not have any third part firewall at all. On Mojave it worked, I guess it is an issue related on Catalina and not valet. Do you had any experience on this topic? Securing or unsecuring the default site does not help. |
Sorry, it was well documented on valet doc on this paragraph https://laravel.com/docs/6.x/valet#sharing-sites ! |




This PR optionally enables a fallback site path for uncaught urls.
It adds a "fallback" command to the CLI:
It also adds the inverse command, "unfallback":
Example use case…
I'm developing a site locally on my Mac and I want to view it on my mobile device which is connected to the same LAN. I could run
valet sharefrom my site's local directory, but because ngrok is painfully slow where I live & work, I runvalet fallbackinstead:On my mobile device, I enter my Mac's LAN IP address and I am now viewing the site I was developing on my Mac. Yay! When I'm done, I run
valet unfallback(orvalet unfallbecause it sounds cooler) and the site I'm developing is no longer viewable by my mobile device:Closes #440