reactjslaravelroutessingle-page-applicationhttp-status-code-405

React Laravel 405 method not allowed


My application has React frontend and Laravel backend. React is deployed in S3 bucket, while Laravel is deployed in EC2 instance. In almost every case, things work perfect on my local and somehow fail in production. It has been driving me crazy. The most recent problem right now is that the route /api/user doesn't fetch user data on production because it says POST method is not allowed. It's not true because on local it's working perfect.

This is the code from production:

React Frontend:

const user = await api()
    .get(CSRF)
    .then(() => api().post(API_USER, body, config));
console.log('user', user);

Laravel Backend:

Route::post('/user', function(Request $request){
 $email = $request->email;
 $user = User::where('email', $email)->get();
 return $user;
});

Route list on EC2 production: enter image description here

I already ran php artisan routes:clear and php artisan optimize:clear

Could anyone please help why this might be happening?

PS. I am using this way to fetch user data because on my local, after login, payload returned data but on production payload data was always empty. No idea why.

EDIT

Screenshot of console: enter image description here

Network: enter image description here

Postman: enter image description here


Solution

  • I was able to solve the problem by restarting the EC2 instance and nginx.