vite-plugin: Dev server ping fails with secured Valet site
- Laravel Vite Plugin Version: 0.2.3
- Laravel Version: 9.x-dev 4d46bda
- Node Version: 16.15.0
- NPM Version: 8.5.5
- Chrome Version: 102.0.5005.115
- Firefox Version: 101.0.1
- Laravel Valet Version: 3.1.7
- macOS Version: 12.3.1 (M1)
Description:
When serving a local development site, e.g. valet-vite.test, using Valet, after the site is secured with HTTPS using valet secure the connection to wss://valet-vite.test:3000 fails, and all the pings to https://valet-vite.test/__vite_ping 404.
The errors look like this (screenshot is Firefox, errors are the same in Chrome).
Steps To Reproduce:
composer create-project laravel/laravel:9.x-dev valet-vite && cd valet-vitevalet link valet-vite && valet secure- add
@vite('resources/js/app.js')toresources/views/welcome.blade.php - set
APP_URLtohttps://valet-vite.test npm install && npm run dev
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (13 by maintainers)
Commits related to this issue
- add https cert and key to quiet vite ping noise see: https://github.com/laravel/vite-plugin/issues/27 — committed to UMN-LATIS/Camino by jxjj 2 years ago
Hey, so I just tried and at least the following
serverconfiguration is needed forhttpsto work and the websocket to connect:The
hostis necessary because otherwise the websocket will try to connect usinglocation.hostname.@jessarcher I think the
hmrhost should always be set, andhttpsshould be auto-determined depending onAPP_URL, likevite-plugin-laraveldoes.I haven’t looked into why
ws://browser-hostnameworks andwss://browser-hostnamedoesn’t, but setting thehostto the dev server’s host works in both cases.This is probably not Valet related. I have the same issue serving the local dev site with Lando (Docker).
I had the same problem, I fixed it by adding the key and certificate as I already did with laravel mix.
I created an article to show this working.
👉 https://dev.to/paulocastellano/how-to-make-vite-valet-and-ssl-works-together-5hbb
I’m not shutting down the idea at all, just sharing a perspective. Will chat to Jess more about it and maybe have a play with the idea a bit more.
Thanks for all the discussion folks ❤️
@jessarcher thanks a lot! Glad this is documented now, and I think accepting the additional certificate is a good workaround.
I still think it makes sense to use
APP_URLto do even more automatically when possible. This won’t cover absolutely every use case, but I think it actually is—usually—directly related to the URL that the site is being viewed at.Thanks for reporting this, @bakerkretzmar.
The
__vite_pingissue is known and will be fixed in Vite 3 as mentioned by @innocenzi.I don’t have a Mac (and therefore Valet) to reproduce the socket issue, but I’ll check it out with @timacdonald’s help tomorrow.
@timacdonald I still think
APP_URLis a good heuristic - it should correspond to most defaults, and one can override theserverconfiguration anyway.I can confirm we still need to accept the certificate, but we indeed need to do that only once. Laravel Vite auto-detects Valet and Laragon certificates and uses them, which reduces the configuration needed by the user to get
httpsworking.I don’t think it’s bad to have good defaults that would work in a lot of cases, even if not all of them.
That’s a good point @timacdonald.
Also, if no one provides a
server.hostsetting, the hot file will gethttps://127.0.0.1:3000(auto-detected from the Vite dev server) while the Vite client will auto-detectwss://valet-vite.test:3000from the browser, meaning that the user would need to accept two certificates, in addition to the one they already have to accept athttps://valet-vite.test.Until we can think of something more reliable, I think we’ll just document adding this to
vite.config.js:And then to make sure to visit the following link to accept the certificate:
This is only an issue with Vite 2.x, the ping works differently in Vite 3.x which will be released in the upcoming days/weeks (see https://github.com/vitejs/vite/pull/6819). I’m not even sure if this is fixable on our side because the ping uses the
baseURL, which must be/.