Skip to content

Instantly share code, notes, and snippets.

@marcomessa
Last active Mar 1, 2022
Embed
What would you like to do?
Avoid Firefox and Safari 404 error in preflight request from Nuxt.js app to Laravel / OctoberCMS API.
// When using Nuxt.js in universal mode, bounded to extra domain API written in OctoberCMS,
// this solves CORS issue in Firefox and Safari (network error during page change)
Route::options('/{any}', function() {
$headers = [
'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
'Access-Control-Allow-Headers'=> 'X-Requested-With, Content-Type, X-Auth-Token, Origin, Authorization'
];
return \Response::make('You are connected to the API', 200, $headers);
})->where('any', '.*');
@bisonbleu
Copy link

bisonbleu commented Dec 7, 2020

Thanks @marcomessa ! This solves my CORS issue.

I'm new to OctoberCMS and I'm afraid I don't have your level of expertise. Can you expand a little so I can better understand what's happening?

  • Is this strictly a development fix or can it be used in production?
  • Is the source of the issue October or FF and Safari?

Thank sagain!

@marcomessa
Copy link
Author

marcomessa commented Dec 7, 2020

I'm glad these notes were able to help someone! In my case the problem was related to how CORS were applied: headers sent did not meet the requirements of firefox or safari. It was not an October issue, if I remember well I used a third party plugin for cors, maybe I misconfigured it or maybe it was its fault! Anyway, I saved in my bookmarks this article which cover the argument more in detail, and offer a more elegant solution.

Happy coding!

@bisonbleu
Copy link

bisonbleu commented Dec 7, 2020

Nice, Thanks!

@jeremymouton
Copy link

jeremymouton commented Jan 20, 2021

🙌

@Incremental92
Copy link

Incremental92 commented Mar 1, 2021

Thanks a lot, it's working also !
I spent many months on CORS and JWT, without help and was seriously considering to move to Strapi which handles JWT natively...

@marcomessa
Copy link
Author

marcomessa commented Mar 1, 2021

Glad to be helpful!

@Andre-ADPC
Copy link

Andre-ADPC commented Mar 1, 2022

Very valuable information. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment