laravel / vite-plugin

Laravel plugin for Vite.
MIT License
790 stars 148 forks source link

CORS Error in Vite Server ( in Public IP ) #301

Closed BlaxKnight closed 1 month ago

BlaxKnight commented 1 month ago

Vite Plugin Version

1.0.5

Laravel Version

11.20.0

Node Version

22.6.0

NPM Version

10.8.2

Operating System

Linux

OS Version

Linux Mint 20.3

Web browser and version

Firefox 128.0.3

Running in Sail?

No

Description

Hi, i am new to vite and i got problem that is related to vite server which it is CORS.

OK, simply what I did was: I port forward my laravel port 8000 + vite port 5174 and using my static ip address to see my website so as always i port forwarded my website to see if there is a problem for who wanted to enter my website with public ip and i got cors error by vite, website loaded completely fine ( like images because i use laravel for including assets )

This is not a problem in local btw!

I tried server.hmr in vite.config.js and nothing happend. because of that i just revert all config.

This is my vite config ( for now )

import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import path from "path";

export default defineConfig({
  server: {
    hmr: {
      host: "localhost",
    },
  },
  plugins: [
    laravel({
      input: ["resources/css/app.css", "resources/js/app.js"],
      refresh: true,
    }),
  ],
});

I am sorry, don't know so much about this stuff. please for the god sake help me i am searching this for whole day. Thank You :)

Steps To Reproduce

.

timacdonald commented 1 month ago

Hi there,

CORS certainly is a painful thing to configure. I've recently been fighting that myself.

That being said, this is a question which can be asked on a support channel and is not specifically a "bug" or "issue" with the Vite plugin. I recommend reaching out for guidance on one of the following channels:

This issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

BlaxKnight commented 1 month ago

Thank You