0

I'm using Laravel Forge with Akamai/Linode (Ubuntu with nginx) to deploy an app built with Laravel.

On my local development environment (which runs Apache), all is good and things run smoothly.

When deploying on the production server, the POST requests to the API get redirected to a GET request to the homepage.

The webserver has a SSL cert from LetsEncrypt (I've read somewhere that it may cause issues). Some other answers on StackOverflow mention that the requests should have/not have a trailing slash. Tried all possible combinations.

With Postman(and any other testing tool out there), POST to the following API endpoint

https://app.mydomain.com/api/import/app/orders

results in a HTML response from a 302 Redirect response

<body>
    Redirecting to <a href="https://app.mydomain.com">https://app.mydomain.com</a>.
</body>

Following that redirect the request gets turned from a POST to a GET. While I understand that the decision of switching the request type might be in the user agent's hands, it's still puzzling how come the redirection happens.

54.86.50.139 - - [18/Jul/2023:10:41:32 +0000] 
"POST /api/import/app/orders/ HTTP/1.1" 
301 162 "https://app.mydomain.com/api/import/app/orders/"
"PostmanRuntime/7.32.3"

Since I don't have much experience with nginx, I've tried to look into the configuration of it.

I would have expected things to work out of the box on a Laravel Forge configuration.

6
  • Can you share your route definition? Maybe you have to login or the request is missing the token or similar? Also, did you change the NGINX config? Commented Jul 18, 2023 at 13:36
  • It's an API request. ` Route::prefix('import/app')->group(function (){ Route::post('/orders', ImportOrdersController::class); Route::post('/deliveries', ImportDeliveriesController::class); }); ` There are no middleware that would redirect, and as I mentioned, on the local environment running Apache this works with no problem The request does not even seem to hit the app to begin with. Default configuration of nginx was not changed. Commented Jul 18, 2023 at 13:45
  • If you try adding a basic endpoint like https://app.mydomain.com/api/test, and you just do return "hi, it works!";, does it work at least? Commented Jul 18, 2023 at 13:55
  • I tried that. Added a /api/test route. The GET request gets through correctly, the POST request gets redirected to homepage with a GET request. Commented Jul 18, 2023 at 15:15
  • 1
    Do not try putting information in comments, edit your question to include the contents of the api.php file and Http/Kernel.php Commented Jul 18, 2023 at 15:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.