• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

462
Views
'http://localhost:3000' has been blocked by CORS policy

API : Laravel and MongoDB for database Front : NuxtJs and Vuetify

I have my own API. When I test my routes on Postman, I had cors error, but I solved with this code in file routes api.php.

header('Access-Control-Allow-Origin:  *');
header('Access-Control-Allow-Methods:  POST, GET, OPTIONS, PUT, PATCH, DELETE');

Maybe, there is a better file to put this code. But I work with Postman. If I need to move this code, tell me please.

Now, my actual problem, on my front site, when i want sign up a new user, I have this error

Blocage d'une requête multiorigine (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur http://127.0.0.1:8000/api/register. Raison : l'en-tête « content-type » n'est pas autorisé d'après l'en-tête « Access-Control-Allow-Headers » de la réponse de pré-vérification des requêtes CORS.

Access to XMLHttpRequest at 'http://127.0.0.1:8000/api/register' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

In my file : config/cors.php I have :

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

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => [],

    'max_age' => 0,

    'supports_credentials' => false,

];

Thanks for your help

Edit Resolved

I have found the answer. I just add : Access-Control-Allow-Headers: 'Content-Type' in api.php

header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, PATCH, DELETE'); header('Access-Control-Allow-Headers: Content-Type') ;
about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error