fetch https 127.0.0.1 throws pages err

I have a pages function that is making a fetch request :
export const onRequest = async () =>
fetch("https://127.0.0.1")
export const onRequest = async () =>
fetch("https://127.0.0.1")
[pages:err] GET /api/proxy: TypeError: fetch failed
at Object.processResponse (/Users/alexander/sandbox/src/github.com/udiaca/u0.vc/node_modules/wrangler/node_modules/undici/lib/fetch/index.js:199:23)
at /Users/alexander/sandbox/src/github.com/udiaca/u0.vc/node_modules/wrangler/node_modules/undici/lib/fetch/index.js:928:38
at node:internal/process/task_queues:141:7
at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
[pages:err] Cause: Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (node:_tls_wrap:1532:34)
at TLSSocket.emit (node:events:527:28)
at TLSSocket.emit (node:domain:475:12)
at TLSSocket._finishInit (node:_tls_wrap:946:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:727:12)
at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17)
[pages:err] GET /api/proxy: TypeError: fetch failed
at Object.processResponse (/Users/alexander/sandbox/src/github.com/udiaca/u0.vc/node_modules/wrangler/node_modules/undici/lib/fetch/index.js:199:23)
at /Users/alexander/sandbox/src/github.com/udiaca/u0.vc/node_modules/wrangler/node_modules/undici/lib/fetch/index.js:928:38
at node:internal/process/task_queues:141:7
at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
[pages:err] Cause: Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (node:_tls_wrap:1532:34)
at TLSSocket.emit (node:events:527:28)
at TLSSocket.emit (node:domain:475:12)
at TLSSocket._finishInit (node:_tls_wrap:946:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:727:12)
at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17)
My localhost https server certs were installed using https://github.com/FiloSottile/mkcert
mkcert -install
mkcert localhost 127.0.0.1 ::1
mkcert -install
mkcert localhost 127.0.0.1 ::1
I have verified that the server is working using firefox, chrome, and curl. How can I get my pages function to recognize these certificates?
GitHub
GitHub - FiloSottile/mkcert: A simple zero-config tool to make loca...
A simple zero-config tool to make locally trusted development certificates with any names you'd like. - GitHub - FiloSottile/mkcert: A simple zero-config tool to make locally trusted develo...
8 Replies
Walshy
Walshy2y ago
I don't think Wrangler has a way to trust an untrusted cert. You could probably add to your system chain
James
James2y ago
I believe you can set the NODE_EXTRA_CA_CERTS env var - at least with default wrangler anyway.
Walshy
Walshy2y ago
oh yeah NODE_EXTRA_CA_CERTS is better than system
James
James2y ago
I'm not entirely certain if that will propagate to pages dev, but it's worth a try
Walshy
Walshy2y ago
Miniflare doesn't do any trust verification itself it should just be undici so should be fine
James
James2y ago
Fingers crossed. https://nodejs.org/api/cli.html#node_extra_ca_certsfile is probably the best reference for that.
Steved
Steved2y ago
It may also be possible to use NODE_OPTIONS=--use-openssl-ca as suggested by https://stackoverflow.com/a/68135600/1129543
Stack Overflow
ssl certificate generated by mkcert is not a full chain
I am using mkcert to generate a self signed certificate for localhost. mkcert -install mkcert localhost This works fine for the browser but if I try and and do a fetch from node, I get this error:
Steved
Steved2y ago
However, when I try this, I get:
cause: Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
at TLSSocket.emit (node:events:390:28)
at TLSSocket._finishInit (node:_tls_wrap:944:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12) {
code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'
cause: Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
at TLSSocket.emit (node:events:390:28)
at TLSSocket._finishInit (node:_tls_wrap:944:8)
at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12) {
code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'