Redirect is resulting in a 500 response

Hi, I’m attempting a 200 redirect from /api to my api service on a different domain but I keep getting a 500 response.

Site name: inspiring-lovelace-45223a
x-nf-request-id: 01FS7XAQ239JJDYF0T8KFZ9G1Q

I have the following netlify.toml file setup and it lives in the root of my project. The second redirect works fine:

  from = "/api"
  to = "https://<site-name>.com/graphql"
  status = 200
  force = true

  from = "/*"
  to = "/index.html"
  status = 200


:method: POST
:path: /api
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cache-control: no-cache
content-length: 370
content-type: application/json
pragma: no-cache
sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36


age: 0
content-length: 0
date: Wed, 12 Jan 2022 19:48:09 GMT
server: Netlify
x-nf-request-id: 01FS7XAQ239JJDYF0T8KFZ9G1Q

Hi @gxcur8

The first thing I would check is if the site works without the redirect in place to ensure the API is working as intended.

Are you making calls to the the API such as /api/something or /api/something/else? If yes, you will need to change the redirect to

  from = "/api/*"
  to = "https://<site-name>.com/graphql/:splat"
  status = 200
  force = true

or if everything needs to go to the /graphql endpoint with the path logic handled by the API internally remove the :splat while leaving the *.

Hi @coelmay, thanks for your help. I have a similar proxy set up locally and it works. This particular endpoint is just the one endpoint and there are no nested paths so all requests get sent to /api as a POST with the request data in the body and I would like that POST to be redirected to https://<site-name>.com/graphql.

Is there any way I could view the server logs related to this request to see where the problem might be?

Are you using Netlify CLI to test this, or have you a separate proxy server running? If the latter, can you try the former.

If the server /api is connecting to returns a 500 error, that is passed through to the browser.

Thanks for the suggestion @coelmay, I had no idea about the Netlify CLI. When I serve the site locally using netlify dev I still get a 500 error, but I did get the following printout in the cli when I attempted to perform the proxied request:

◈ Proxying to https://<sitedomain>/graphql
[HPM] Proxy created: /  -> https://<sitedomain>
[HPM] Error occurred while proxying request localhost:8888/graphql to https://<sitedomain>/ [UNABLE_TO_VERIFY_LEAF_SIGNATURE] (

I tried setting both NODE_TLS_REJECT_UNAUTHORIZED = '0' and NODE_EXTRA_CA_CERTS = <path-to-ca-cert> but I still get the same error.

If you don’t run through the proxy (locally using Netlify CLI, or when deployed to Netlify) does everything work as intended?

Yes, I have a webpack setup for local development and it works fine. I’ve also tested with curl.

Without being able to inspect/test myself, it’s hard to diagnose. Can you share either the repository you are deploying from or a minimal reproduction.

1 Like

Is there someway I can inspect the error myself? If not, is there someone I can reach out to in order to look up the error for me?

Hey @gxcur8,

We see this error in your logs:

x509: certificate signed by unknown authority

This could indicate that the SSL certificate for the destination server is either working incorrectly or not supported by us.

Ok, thanks for looking into it. As an fyi, i went over to Vercel, pushed up my rewrites configs and it all worked on the first try.

Just as an update, there was a pull request merged around the same time as this thread was opened which claims to have fixed this issue. So in case anyone else stumbles upon the same issue, let us know.