Next.js Discord

Discord Forum

How could I get around the self-signed certificate error?

Answered
American Curl posted this in #help-forum
Open in Discord
American CurlOP
Hi, I switched to connect to the backend server which has a self-signed certificate. Then the Error: self-signed certificate error occurred. How could I get around it? This is how I configured to use it in next.config.mjs:
async rewrites() {
  return [
    {
      source: '/api/:path',
      destination: 'https://mydomain/api/:path'
    }
  ]
}

It worked with the HTTP server, so the error implied that it was about the HTTP certificate. So how could I get around it in development? Thanks.
Answered by Anay-208 | Ping in replies
Hmm, why are you rewriting requests, why don't you directly send to mydomain
View full answer

32 Replies

American CurlOP
yes. I just upgraded to use HTTPS which has a self-signed certificate.
Hmm, why are you rewriting requests, why don't you directly send to mydomain
Answer
American CurlOP
There's CORS issue if I send to mydomain, so this avoids fixing the CORS issue😅
American CurlOP
It's been deployed by the backend developer that the API and the frontend portal in the same nginx.
American CurlOP
Thanks, I will check out.
It needs to be added to the backend
@Anay-208 | Ping in replies https://www.npmjs.com/package/cors
Once your issue is resolved, mark solution please
American CurlOP
How can I mark it?
I see.
Are there any other solutions?
I think this should be common case using rewrites to redirect to the backend.
It's like a proxy.
or some sensitive info, which shouldn't be shown to client
American CurlOP
I searched online. There're some solutions like adding NODE_TLS_REJECT_UNAUTHORIZED=0, but none is workign.
@Anay-208 | Ping in replies https://www.npmjs.com/package/cors
American CurlOP
Is this used in backend to fix the CORS issue?
yes
@American Curl I searched online. There're some solutions like adding `NODE_TLS_REJECT_UNAUTHORIZED=0`, but none is workign.
even if you post on stackoverflow, your post will get -1 since this is not a good approach
@American Curl Let me know if you need any further help regarding this.

If you want to proxy through your nextjs app(NOT RECOMMEND AT ALL), a approach would be to:
- create a api route, /api/[...slug]/route.ts
- Get the slug, and send the request to domain/slug, with same body & headeres
American CurlOP
Thanks. I just started using this. And I didn't use this feature yet.
We just switched to Static Exports to build the application, so I'm not sure if it's supported feature.
it won't work then
With static
American CurlOP
Meantime, I'm talking with backend guys to help fix CORS issue from backend then I can access the API directly.
I'm asking to make sure if there are solutions for the rewrites case.
Ping me if you've any more queries
in a different thread
American CurlOP
Great, thanks.