Netlify Backend Proxy Redirect Returns 404 Not Found

Hello. I am having issues with proxying a POST request to a remote backend server hosted on an EC2 instance. I have deployed a Vite + React frontend to Netlify and need to proxy API calls.

Here is the website:
https://main–frabjous-heliotrope-3148d9.netlify.app/

To make the call in question:
Click “Guest User” → Type in any text → Click “Interpret”

I have set up redirect rules in my netlify.toml file as follows (taken from deploy files):

[[redirects]]
from = "/api/generate_image"
to = "http://[redacted IPv4 address]:8080/generate_image"
status = 200
force = true
conditions = {Method = ["POST"]}

[[redirects]]
from = "/*"
to = "/index.html"
status = 200

The deploy summary show that the redirects rules have been successfully processed. I have set up CORS configs on my server and tested that local calls to it work.

After deploying my frontend to Netlify, it tries to make a call to my remote API but I get a 404: Not Found error.

Request URL:
https://main--frabjous-heliotrope-3148d9.netlify.app/api/generate_image
Request Method:
POST
Status Code:
404 Not Found
Remote Address:
[2600:1f1c:446:4900::64]:443
Referrer Policy:
strict-origin-when-cross-origin
POST https://main--frabjous-heliotrope-3148d9.netlify.app/api/generate_image 404 (Not Found)

Here is the part of source code from the frontend that makes the call:

const apiUrl = '/api/generate_image';

        const requestBody = {
            userPrompt: dreamText,
        };

        fetch(apiUrl, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(requestBody),
        })

Here is the code being executed in the browser (index-fdcb5054.js):

fetch("/api/generate_image", {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify({
                userPrompt: e
            })
        })

I’ve followed the directions on the redirects and proxy documentation as well as other forum posts the best I can and still cannot figure out why I am getting a 404 error.

This is invalid, not sure where you got it from. I’d suggest removing that and trying.