Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Why don't the docs mention anything about the paths array in cors.php?

I feel like I'm doing something wrong since the only way I managed to make my Vue app successfully send requests to the Laravel backend is after adding the needed routes (/test in my example) to the paths array in cors.php:

   'paths' => ['api/*', 'sanctum/csrf-cookie', '/test'],

Before I added it, I was getting this error message on the frontend:

Access to XMLHttpRequest at 'http://localhost/test' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Is there a reason it's not mentioned in the docs? Or I am doing something wrong?

Ty!

0 likes
10 replies
Snapey's avatar

You have two hosts? localhost and localhost:3000 ? They are seen as different servers

1 like
Ligonsker's avatar

@Snapey Yes because I created a Vue CLI app separately which is served on localhost:3000

And now that I think about it, I read that part of the docs wrong:

If you are accessing your application via a URL that includes a port (127.0.0.1:8000), you should ensure that you include the port number with the domain.

This means that the Laravel itself has the port 8000, not the separate Vue.

So I guess the docs expect that the frontend would have same domain (and port), but different sub-domain, i.e., the frontend would be localhost, and Laravel backend would be perhaps backend.localhost?, and then I would not need the /test route in the paths array?

Snapey's avatar

@Ligonsker The frontend does not have a domain and port.

Are you running a separate node server to serve frontend content?

1 like
Ligonsker's avatar

@Snapey Yes it's separate. So in production of course front end would not have port, but when using Vue in development it starts the server (frontend) on localhost:3000

I guess I should change it so Vue starts on port 80, and Laravel on port 8000? (But then they will still be separate actually)

Snapey's avatar

@Ligonsker I won't pretend to understand why you need two servers. Did you consider inertia?

2 likes
Ligonsker's avatar

@Snapey But what are my other options? If Inertia did not exist, how would you make an SPA with Laravel? Could you do it on the same server? If so then I would change it

*Edit: Now that I think of this: Why does Vue run on localhost:3000? It doesn't really need a server, it's only compiled JS/html/css, so why do I need a server? I must be doing something wrong

jlrdw's avatar

@Ligonsker passport is also an option. But an SPA doesn't have to be from an API. And an API doesn't just send data to a SPA.

2 likes
Ligonsker's avatar

@jlrdw Can you explain what does it mean in the last 2 sentences? I got confused 😃 About Passport: Why do you recommend this over Sanctum for SPA? Just because in my case it's actual 2 separate projects (backend and frontend)?

Please or to participate in this conversation.