laravel / vite-plugin

Laravel plugin for Vite.
MIT License
799 stars 151 forks source link

Error while using Inertia Vue: The Vite server should not be accessed directly. #96

Closed Bosphoramus closed 2 years ago

Bosphoramus commented 2 years ago

Description:

I have scaffolded an Inertia Vue SSR application using Laravel breeze with the following breeze command:

php artisan breeze:install vue --ssr

Everything works correctly but there is a little bug that bothers me, almost all the time, when i start the dev server i get the following warning in the console: The Vite server should not be accessed directly. Your Laravel application's configured APP_URL is: X

Im not accessing the vite dev server url, im using Laravel Valet and im accessing the "fancy" vhost url.

Steps To Reproduce:

Install Laravel and enter the directory:

laravel new test && cd test

Require Breeze

composer require laravel/breeze

Scaffold a Breeze Inertia Vue SSR app using

php artisan breeze:install vue --ssr

Run the dev server

npm install && npm run dev

Go to your app

Using your web browser navigate to your app, usually the APP_URL that the dev server suggests

Stop the dev server

WITHOUT CLOSING YOUR APP TAB ON YOUR BROWSER Ctrl + c on the console, to close the dev server

Start it again

npm run dev

Now you should be seeing the warning, which shouldnt be showing because the user never accesed the dev server URL directly

Just noticed this also happens scaffolding the Breeze Vue Inertia application without SSR.

jessarcher commented 2 years ago

I believe this is because Vite 3 now pings the root URL when the HMR server disappears.

It's a bit hard to reliably detect whether the user is visiting it vs. it being pinged by the Vite client, as the requests are both made by the browser.

I'm inclined to remove the console warning as the index page we serve should hopefully be enough to guide users towards running a dev server for Laravel.

jessarcher commented 2 years ago

I've created #98 to address this. Feel free to continue discussion over there :slightly_smiling_face:

Bosphoramus commented 2 years ago

Ok, thank you @jessarcher ☺️