Laravel vite doesnt work

Access to script at 'https://workstations.cloud.google.com/devshell/gateway/oauth?_workstationRedirectOrigin=https%3A%2F%2F8000-idx-basta-1716613881350.cluster-7ubberrabzh4qqy2g4z7wgxuw2.cloudworkstations.dev&state=eyJ0b2tlbiI6IkhyR2ZPQ0JkMF8zbjhLUjFJS3U0bXciLCJ0YXJnZXRfaG9zdCI6IjUxNzMtaWR4LWJhc3RhLTE3MTY2MTM4ODEzNTAuY2x1c3Rlci03dWJiZXJyYWJ6aDRxcXkyZzR6N3dneHV3Mi5jbG91ZHdvcmtzdGF0aW9ucy5kZXYiLCJhdXRodXNlciI6IiIsIndvcmtzdGF0aW9uX25hbWUiOiJwcm9qZWN0cy9tb25vc3BhY2UtNC9sb2NhdGlvbnMvYXNpYS1lYXN0MS93b3Jrc3RhdGlvbkNsdXN0ZXJzL3dvcmtzdGF0aW9uLWNsdXN0ZXItOC93b3Jrc3RhdGlvbkNvbmZpZ3MvbW9ub3NwYWNlLWNvbmZpZy13ZWIvd29ya3N0YXRpb25zL2lkeC1iYXN0YS0xNzE2NjEzODgxMzUwIiwid29ya3N0YXRpb25fY29uc3VtZXJfcHJvamVjdF9udW1iZXIiOiIzOTA5NDU2NTY5OTEifQ' (redirected from 'https://5173-idx-basta-1716613881350.cluster-7ubberrabzh4qqy2g4z7wgxuw2.cloudworkstations.dev/@vite/client') from origin 'https://8000-idx-basta-1716613881350.cluster-7ubberrabzh4qqy2g4z7wgxuw2.cloudworkstations.dev' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

When I run php artisan server and npm run dev together for spinning up the vite development server, it seems it redirect even its in the correct url in the first place
image

I even adjust to allow cors to the vite dev server but wont work because it needs to do oauth

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import react from '@vitejs/plugin-react';

export default defineConfig({
    plugins: [
        laravel({
            input: 'resources/js/app.tsx',
            refresh: true,
        }),
        react(),
    ],
    server: {
        port: 5173, // Specify the port here
        cors: true, // Enable CORS
        // Alternatively, for more fine-grained control, you can use:
        // cors: {
        //     origin: '*', // Allow any origin
        //     methods: ['GET', 'POST', 'PUT', 'DELETE'], // Allowed methods
        //     allowedHeaders: ['Content-Type', 'Authorization'], // Allowed headers
        // },
        configureServer: (server) => {
            server.middlewares.use((req, res, next) => {
                res.setHeader('Access-Control-Allow-Origin', '*');
                res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
                res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
                next();
            });
        }
    }
});
1 Like

Is it because of different ports? I feel like this should work but the blocker is the oauth redirection for the vite dev server
image

Got the same problem as u and Iā€™m runnin vite build watch to hotfix this for now :sweat_smile: