1

enter image description here

I am using Nuxt.js, Laravel, and Laravel Sanctum for API development learning projects. Now, I have been stuck with this error for a few days. I know that Laravel Sanctum will handle everything on config/cors.php with some changes like I said at Nuxt.js - No 'Access-Control-Allow-Origin' header is present on the requested resource

Then,

Why I am facing this CORS error? Does anyone know something?

Please guide me, it will be helpful for me.

JS TECH
  • 1,556
  • 2
  • 11
  • 27
  • Does this answer your questions - https://stackoverflow.com/questions/39429462/adding-access-control-allow-origin-header-response-in-laravel-5-3-passport ? – mk23 Jun 24 '21 at 01:57
  • You need to set Access-Control-Allow-Origin headers at the origin. – mk23 Jun 24 '21 at 01:58
  • Not help, both are the same thing using middleware or cors.php – JS TECH Jun 24 '21 at 01:59
  • Set `Access-Control-Allow-Origin: *` headers in the code and see if that works. – mk23 Jun 24 '21 at 02:07
  • 2
    Laravel already set `'allowed_origins' => ['*']` by default at cors.php, then why we need to set it again. – JS TECH Jun 24 '21 at 02:09
  • CORS need to be set on the origin api where you are pulling the information. `api.technojs.com` You can read more about this https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS – mk23 Jun 24 '21 at 02:39
  • `api.technojs.com` is my Laravel API project, `alpha.technojs.com` is Nuxtjs frontend project. I know that CORS needs to be set on `api.technojs.com` but it's already set on `cors.php`. Then why it's not working. – JS TECH Jun 24 '21 at 02:48
  • @JSTECH were you able to solve it? I'm facing the same issue with my React app. – Amandeep Singh Nov 02 '21 at 14:42
  • @AmandeepSingh Sadly say NO but in my case, it's could be different issues. I think the Frontend JavaScript Framework needs a full Nodejs server to handle CORS in the backend. Due to the absence of Nodejs on my static server, it might be thrown an error. – JS TECH Nov 04 '21 at 00:14

1 Answers1

0

This may or may not help.... but I suffered the same issue not locally, not on test, but on my PROD deployment of a project. What solved it for me is CHOWN'ing the entire Laravel project to 'www-data' . When my user was the owner of the Laravel project I kept getting "No 'Access-Control-Allow-Origin' header is present on the requested resource." like you. After CHOWN'ing it to'www-data' it worked as usual.

I can't tell you why this is the case besides something with PHP being represented as the "www-data" user or something like that ( I'm not that smart ). But hope this helps!

EDIT: my project is React <-> Laravel, my Cors.php was configured correctly the entire time.