jn-jairo / laravel-ngrok

Share Laravel application with ngrok.
MIT License
92 stars 12 forks source link

Enhance to work with Vite and hmr #17

Closed labu closed 3 months ago

labu commented 3 months ago

Is your feature request related to a problem? Please describe. This works when not running Vite. This would be such a useful feature if it can be also expanded to make it work with Vite and its hot module replacement (hmr) even when using ngrok.

Describe the solution you'd like Aaron Francis did this in a YouTube video, but I could not make it work following the video. https://youtu.be/pT7e31DMTYY

Thank you very much for this project. It has been incredibly helpful.

jn-jairo commented 3 months ago

This package doesn't use named tunnels from the yml config file, it gets the parameters from the command line or from your app.url configuration.

It is meant for simple cases and creates the tunnel using the command ngrok http not the ngrok start that is the one used for named tunnels.

If you want to start ngrok with more complex settings you can do it directly from the ngrok command and the package will handle the requests anyway, if they come from any of the ngrok domains (ngrok.io, ngrok-free.app, ngrok-free.dev, ngrok.app, ngrok.dev).

The video you linked uses two tunnels and overwrite the hot file with the second tunnel url, this is beyond the scope of this project.

This package fixes the assets url automatically if the request comes from the ngrok domains, so that part of the video you could skip, but getting the url for the hot file is tricky, I don't think it is possible using the free version of ngrok, because the free version only gives you random urls and one tunnel.

As I understand you cannot make the code of the video works unless you have the multiple tunnels and named urls that paid ngrok offers.

If you have access to the ngrok features that the code from the video requires you should be able to make it work.

Good luck on your coding, I hope you manage to make it work.

labu commented 3 months ago

Thank you so much. I managed to make it work with Zrok since, unlike ngrok, it gives you multiple tunnels and fixed URLs. If you're interested, please check out my sample project demonstrating the setup with Zrok at laravel-vite-hot-reload-share. Ngrok is still fast and excellent for single tunnels though.