question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

๐Ÿ› BUG: pages dev with https cannot proxy request (to https server)

See original GitHub issue

What version of Wrangler are you using?

2.1.6

What operating system are you using?

MacOS

Describe the Bug

Iโ€™m unable to proxy to vite when using --local-protocol https step to reproduce:

npm create vite@latest my-vue-app -- --template vue-ts
cd my-vue-app
npm i -D wrangler
npx wrangler pages dev --local-protocol https -- npx vite --https

in vite.config.ts add:

  server:{  https: {
    key: fs.readFileSync('./localhost.internal.tld.key'),
    cert: fs.readFileSync('./localhostinternal.tld.pem')
  }}

or with an automatic self signed certificate (with @vitejs/plugin-basic-ssl plugin):

import mkcert from '@vitejs/plugin-basic-ssl'
โ€ฆโ€ฆโ€ฆ
 plugins: [ 
       mkcert(),vue() ],
 server: { https: true },

Open https://127.0.0.1:8788 On console:

๐Ÿšง 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
Running npx vite...
Sleeping 5 seconds to allow proxy process to start before attempting to automatically determine port...
To skip, specify the proxy port with --proxy.
[proxy]: 
  VITE v3.1.3  ready in 354 ms


[proxy]:   โžœ  Local:   http://127.0.0.1:5173/
  โžœ  Network: use --host to expose

Automatically determined the proxy port to be 5173.
No functions. Shimming...
โ–ฒ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.


โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ [b] open a browser, [d] open Devtools, [c] clear console, [x] to exit                                                                                                                                          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Starting inspector on 0.0.0.0:9229 failed: address already in use
[pages:wrn] Service bindings are experimental. There may be breaking changes in the future.
[pages:inf] Generating new self-signed certificate...
[pages:inf] Updated `Request.cf` object cache!
[pages:inf] Worker reloaded! (322B)
[pages:inf] Listening on 0.0.0.0:8788
[pages:inf] - https://127.0.0.1:8788
[pages:inf] - https://192.168.2.42:8788
[pages:err] Error: Could not proxy request: TypeError: fetch failed
    at file:///Users/--/my-vue-app/node_modules/wrangler/miniflare-dist/index.mjs:5995:27
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Fetcher.fetch (/Users/--/my-vue-app/node_modules/@miniflare/core/src/plugins/bindings.ts:130:17)
    at Object.fetch (/Users/--/my-vue-app/node_modules/wrangler/templates/pages-shim.ts:6:20)
    at EventTarget.[kDispatchFetch] (/Users/--/my-vue-app/node_modules/@miniflare/core/src/standards/event.ts:385:13)
    at Server.<anonymous> (/Users/--/my-vue-app/node_modules/@miniflare/http-server/src/index.ts:298:20)
GET / 502 Bad Gateway (70.85ms)

On browser: [wrangler] Could not proxy request: TypeError: fetch failed

I tried to configure vite to listen to a https port with the same resule

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
eltoriocommented, Sep 23, 2022

I found a workaround I produced a certificate with:

            X509v3 Subject Alternative Name: 
                DNS:localhost.internal.tld, DNS:localhost., IP:127.0.0.1

signed by our subca internal.tld certificate I added an environment variable in my VsCode environment

"NODE_EXTRA_CA_CERTS":"${workspaceFolder}/subca.internal.tld.pem",

And finally it works !

So for using --local-protocol https to https server you must have a valid signed certificate witch it does not make sense. I think the Agent of undici.fetch must include

Agent({ connect: { rejectUnauthorized: false } })

0reactions
eltoriocommented, Nov 13, 2022

Still same with 2.2.1

I updated my test repo for using my (worst/ugly/โ€ฆ) workaround. only once issue:

npm run create-cert

next use as usual:

npm run dev
#or
npm run build && npm run preview

package.json

{
  "name": "my-vue-app",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "create-ca":"openssl req -x509 -sha256 -days 3562 -nodes -newkey rsa:4096 -subj '/CN=demo.highcanly.club/C=FR/L=Flers-en-Escrebieux' -keyout localhost-rootCA.key -out localhost-rootCA.pem",
    "create-key":"openssl genrsa 4096 > localhost.key",
    "create-csr":"openssl req -new -key localhost.key -subj '/CN=localhost/C=FR/L=Flers-en-Escrebieux'  > localhost.csr",
    "create-crt":"openssl x509 -req -in localhost.csr -out localhost.pem -sha256 -CA localhost-rootCA.pem -days 3600 -CAkey localhost-rootCA.key -CAcreateserial -CAserial localhost-rootCA.srl",
    "create-cert":"npm run create-ca && npm run create-key && npm run create-csr && npm run create-crt",
    "dev": "NODE_EXTRA_CA_CERTS=`pwd`/localhost-rootCA.pem npx wrangler pages dev --local-protocol https -- npx vite",
    "build": "vite build",
    "preview": "NODE_EXTRA_CA_CERTS=`pwd`/localhost-rootCA.pem npx wrangler pages dev --local-protocol https -- npx vite preview"
  },
  "dependencies": {
    "vue": "^3.2.45"
  },
  "devDependencies": {
    "@vitejs/plugin-basic-ssl": "^0.1.2",
    "@vitejs/plugin-vue": "^3.2.0",
    "plugin": "^0.3.3",
    "typescript": "^4.8.4",
    "vite": "^3.2.3",
    "vue-tsc": "^1.0.9",
    "wrangler": "^2.2.1"
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

React App Proxy Error: Could Not Proxy Request
I cloned the repo and did npm install in both the root folder and the client folder. When I enter npm run dev,...
Read more >
Using the proxy | Guide | ArcGIS API for JavaScript 3.42
The proxy consists of server-side code that runs on your web server. Your browser based web application sends the request to the proxy...
Read more >
Why you should use a proxy server with Create React App
Some examples of proxying requests in React applications are listed below. First is requesting HTTPS APIs in development ( https://localhost ).
Read more >
Troubleshooting SSL - GitLab Docs
The echo command sends a null request to the server, causing it to close the connection ... ERROR: Not a certificate: /opt/gitlab/embedded/ssl/certs/FILE.
Read more >
Troubleshooting - Wiki.js - requarks.io
Cause: You are most likely using a reverse proxy such as nginx or apache. Resolution: Increase your reverse proxy configuration for file uploads....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found