A colleague of mine has the same problem. Have you found a solution yet?
Apr 9, 2023
2
Level 4
Laravel Vite issues with CORS policy
Hi Picking up Laravel Vite for the first time and working through issues getting it working on my development set up. I have a fresh install of Laravel 10 and developing using Laravel Homestead.
I first had problems with a Connection Refused which I overcame with updating the config file as follows based on previous questions with the forum:
import { defineConfig } from 'vite';
import laravel, { refreshPaths } from 'laravel-vite-plugin';
export default defineConfig({
server: {
host: '192.168.56.56', // replace with the IP address of the Homestead machine
https: false,
cors: false,
hmr: {
host: '192.168.56.56', // replace with the IP address of the Homestead machine
}
},
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: [
...refreshPaths,
'app/Http/Livewire/**',
],
}),
],
});
This appears to now work to a degree and I can get the assets built when I run npm run dev
However the browser is reporting multiple errors due to CORS issues:
Acess to script at 'http://192.168.56.56:5173/resources/js/app.js' from origin 'http://golf.local' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
How can I configure this correctly to enable my site to access and overcome the CORS issue?
ANy help appreciated
Thank you
Please or to participate in this conversation.