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-vite
valet link valet-vite && valet secure
- add
@vite('resources/js/app.js')
toresources/views/welcome.blade.php
- set
APP_URL
tohttps://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
server
configuration is needed forhttps
to work and the websocket to connect:The
host
is necessary because otherwise the websocket will try to connect usinglocation.hostname
.@jessarcher I think the
hmr
host should always be set, andhttps
should be auto-determined depending onAPP_URL
, likevite-plugin-laravel
does.I haven’t looked into why
ws://browser-hostname
works andwss://browser-hostname
doesn’t, but setting thehost
to 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_URL
to 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_ping
issue 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_URL
is a good heuristic - it should correspond to most defaults, and one can override theserver
configuration 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
https
working.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.host
setting, 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:3000
from 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
base
URL, which must be/
.