laravel / valet

A more enjoyable local development experience for Mac.
https://laravel.com/docs/valet
MIT License
2.52k stars 698 forks source link

Add a new share tool, cloudflared #1467

Closed rcknr closed 3 months ago

rcknr commented 10 months ago

This adds a new way of sharing websites using cloudflared, specifically something called "quick tunnels". These don't require registration and are free of charge to use. It's also possible to use your own domain for sharing by authenticating and configuring a custom tunnel. However, the basic usage requires zero setup.

mattstauffer commented 10 months ago

Thanks so much for this PR! I hope to get to it this week, but if not, It'll be a few weeks before I get back to it. Anyone else is welcome to test it out and weigh in whether it works for you!

rcknr commented 10 months ago

Hi @mattstauffer! Thanks for taking care of this. Hope you'll have some time this week.

rcknr commented 8 months ago

@mattstauffer any chance for this one to get reviewed?

mattstauffer commented 5 months ago

@rcknr I'm sorry for the delay. It's on my todo list this week.

rcknr commented 4 months ago

@mattstauffer Any chance this gets merged?

mattstauffer commented 3 months ago

Thank you so much for your patience!!

Testing:

Results: 502 Bad Gateway Unable to reach the origin service. The service may be down or it may not be responding to traffic from cloudflared

The CLI logs show: 2024-08-24T20:59:14Z ERR error="Unable to reach the origin service. The service may be down or it may not be responding to traffic from cloudflared: dial tcp [::1]:443: connect: connection refused" connIndex=0 event=1 ingressRule=0 originService=https://localhost

I'll be testing around to figure out the origin, but just wanted you to see that I am indeed looking at it!

mattstauffer commented 3 months ago

I secured the site and it worked, so I suspect the tunnels either A) require the site to be secured or B) require our code to be a bit smarter depending on whether the site is secured. Will dig into it a bit.

mattstauffer commented 3 months ago

Looks like the new logic around $SECURED wasn't actually working; it marked every site as secured, rather than assigning $SECURED the exit code of the command, so we had to refactor that. Also refactored the implementation of the currentTunnelUrl to be less nested and added a few comments so everything's more clear. But it works now! Thanks for your PR and your patience, @rcknr!

rcknr commented 3 months ago

@mattstauffer Thanks for finally finding time to get this merged!

danijelk commented 1 month ago

Great PR @rcknr Thanks for passing it through @mattstauffer

After testing it and figuring out how the cloudflare tunnels work, the easiest way to run a private tunnel is to add --name TunnelName after the cloudflared command (valet share).

But cause of the valet bash script stripping any -- arguments from valet share, it doesn't seem possible without rewriting the $PARAMS handling.


So just as a reference for others, since the readme for cloudflare is quite big.

valet share runs the following: cloudflared tunnel --no-tls-verify --url "http://localhost" --http-host-header "local-dev.test"

which runs in the trycloudflare.com url mode, to use your own tunnel (after tunnel login + tunnel create + tunnel route) simply append the name

cloudflared tunnel --no-tls-verify --url "http://localhost" --http-host-header "local-dev.test" --name tunnelName

rcknr commented 1 month ago

@danijelk Thanks! I have submitted #1495 to fix parameters handling but it wasn't merged yet. It seems to me that Valet is being abandoned which is a pity.

danijelk commented 1 month ago

@danijelk Thanks! I have submitted #1495 to fix parameters handling but it wasn't merged yet. It seems to me that Valet is being abandoned which is a pity.

Oh nice, can't speak much for the valet part, but awesome to see people that care still try to help 💪