CORS error with flask

I created a Flask app that uses a model from HuggingFace and everything worked fine locally but whenever I deploy the app here on Render and try to use it I get CORS error although I’s enabling CORS in the Flask app. I searched the web a lot and I couldn’t find any solution. Here’s the source code for the application for more context: Anwar11234/summarization-api (github.com)

Hi there,

Your code config looks like it should allow all origins to access your service. That being said, if your request fails and the response is returned from our proxy (i.e., 502 errors), it will not have CORS headers. Please check the status code of the request you are making to your service.

Regards,

Keith
Render Support, UTC+10 :australia:

It does return 502 error. How should I handle that? Here’s the JS code that uses the API:

async function summarizeText(text) {
    const url = 'https://summarization-api-fastapi.onrender.com/summarize';  
    const data = { text };
    console.log(data)
    const response = await fetch(url, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(data),
    });
    
    if (!response.ok) {
      throw new Error(`Error: ${response.status}`);
    }
  
    const summaryData = await response.json();
    return summaryData.summary;
  }
  
  // Example usage
  const userText = "This is a long sentence that need to be summarized";
  summarizeText(userText)
    .then(summary => {
      console.log("Summary:", summary);
    })
    .catch(error => console.error("Error:", error));

and here’s the error message:

Hi there,

You will need to resolve the 502 error on your server side.

On the client side, you could have specific code to handle the 502 responses better and display an error page, but it would still be an error.

Can you please open a ticket with us directly from our dashboard so we can look into the specific service returning the 502 errors?

Regards,

Keith
Render Support, UTC+10 :australia:

Sure. How can I open a ticket?

Hi there,

You can open a ticket by using the help menu at the top of our dashboard.

Regards,

Keith
Render Support, UTC+10 :australia:

Hi Keith,

I have the exact same problem. Could you help me with this regard? I already opened a ticket but the person who replied did not yet provide a valid solution. Since you already worked on this issue you might already have it figured out.

Best,
Paolo

Hi ahmed,

have you already figured it out? I have the exact same problem. Locally everything works fine.

Here my Github repo for reference: latest_GPT/frontend/.env.production at main · PaoloOppelt/latest_GPT · GitHub

Hi there,

Looks like your service is running out of memory. Requests to your service while in an unhealthy state will respond with a 502. You will likely want to use the --max-old-space-size option on NodeJS to limit your heap space usage. For a service with 512MB of memory, I would recommend setting this to 420 for a service with 2GB of memory, set it to 1536 and per the NodeJS docs.

Please use your other ticket to follow up on this.

Regards,

Keith
Render Support, UTC+10 :australia:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.