My client side is converting all responses from my backend to html documents. Even when they are sting, json, etc. I think something is wrong with my render config

I have uploaded a static site built with react on site.render.com and a nodeJS web service deployed on site-server.render.com. The response that my static website is getting is incorrect and I have reasons to believe that the bug lies somewhere in the render config in my frontend. . My server has a response as follow:

// server.js
export const test = async (req: Request, res: Response) => {
    console.log('test point hit', req.session.id)
    res.sendStatus(201)
    return
}
// frontend.jsx
<Button
    onClick={() => {
        axios.get('/api/test', { withCredentials: true }).then(res => {
            console.log('res from logger is:', res.data, res)
        })
    }}
>
    logger
</Button>

So the expected response is obviously a 404 or a 201 but instead when I console.log(response) on my client site I get an entire html document with status code 200. If I use insomnia to test my server’s response, i get an expected and correct response. So I think the issue lies on the deployed version on the client side.

Another thing to note is that console.log('test point hit') does not appear in the logs on my server side.

If it matters, I have setup two rewrite rules on my client.

  • 1 rewrite /api/ to destination site-server.com
  • 2 rewrite /* to destination /index.html

My website’s routes are working and pages are rendering as expected. Also, this behavior of getting a html document back does not occur during development on localhost. Even in places where I should receive string or json, I’m receiving html documents.

Hi there,

Static Sites are designed to only return static assets like HTML, CSS, etc. It sounds like you might be better off trying a Web Service, where server-side code can be run dynamically.

Let us know if you have any further questions.

Regards,
Mike


Render Support Engineer, MT (UTC-7)

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