Skip to content

Instantly share code, notes, and snippets.

@marcomessa
Last active March 1, 2022 16:23
Show Gist options
  • Save marcomessa/54d077a0208439f5340126ff629a3718 to your computer and use it in GitHub Desktop.
Save marcomessa/54d077a0208439f5340126ff629a3718 to your computer and use it in GitHub Desktop.
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', '.*');
@marcomessa
Copy link
Author

marcomessa commented Mar 1, 2021

Glad to be helpful!

@Andre-ADPC
Copy link

Very valuable information. Thanks!

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