How could I get around the self-signed certificate error?
Answered
American Curl posted this in #help-forum
American CurlOP
Hi, I switched to connect to the backend server which has a self-signed certificate. Then the
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.
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
Hmm, why are you rewriting requests, why don't you directly send to
mydomain
32 Replies
So If I'm right, you are rewriting a request to a different website.
Is the
Is the
mydomain
hosted by you?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😅fix the CORS issue then, use npmjs package cors
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
With this approach, it might use more memory rewriting requests
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.
No, it is only if an api key is being passed
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.Is this used in backend to fix the CORS issue?
yes
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
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 & headeresAmerican 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.