bartlomieju / vite-deno-example

Example of using Vite with Deno
https://vite-deno-example.deno.dev
163 stars 7 forks source link

🐞 Server proxy config got error! #7

Open chioio opened 1 year ago

chioio commented 1 year ago

App with backend api proxy got error.

//  vite.config.mts

export default defineConfig(({ mode }) => ({
  server: {
    proxy: {
      '/api': {
        target: 'http://xxx.xxx.xxx.xxx:8000/api,
        changeOrigin: true,
      }
    }
  }
}))

Error:

TypeError: Invalid URL: 'http://xxx.xxx.xxx.xxx:8000/api/auth/whoami'
    at getSerialization (ext:deno_url/00_url.js:89:11)
    at new URL (ext:deno_url/00_url.js:359:27)
    at new Request (ext:deno_fetch/23_request.js:300:25)
    at ext:deno_fetch/26_fetch.js:418:27
    at new Promise (<anonymous>)
    at fetch (ext:deno_fetch/26_fetch.js:414:18)
    at ClientRequest._final (ext:deno_node/http.ts:163:29)
    at Object.runMicrotasks (ext:core/01_core.js:830:30)
bartlomieju commented 1 year ago

What Deno version are you using? I can create a URL like that with no problem in Deno v1.33.2:

❯ deno
Deno 1.33.2
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> const u = new URL('http://xxx.xxx.xxx.xxx:8000/api/auth/whoami')
undefined
> u
URL {
  href: "http://xxx.xxx.xxx.xxx:8000/api/auth/whoami",
  origin: "http://xxx.xxx.xxx.xxx:8000",
  protocol: "http:",
  username: "",
  password: "",
  host: "xxx.xxx.xxx.xxx:8000",
  hostname: "xxx.xxx.xxx.xxx",
  port: "8000",
  pathname: "/api/auth/whoami",
  hash: "",
  search: ""
}
>
chioio commented 1 year ago

What Deno version are you using? I can create a URL like that with no problem in Deno v1.33.2:

❯ deno
Deno 1.33.2
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> const u = new URL('http://xxx.xxx.xxx.xxx:8000/api/auth/whoami')
undefined
> u
URL {
  href: "http://xxx.xxx.xxx.xxx:8000/api/auth/whoami",
  origin: "http://xxx.xxx.xxx.xxx:8000",
  protocol: "http:",
  username: "",
  password: "",
  host: "xxx.xxx.xxx.xxx:8000",
  hostname: "xxx.xxx.xxx.xxx",
  port: "8000",
  pathname: "/api/auth/whoami",
  hash: "",
  search: ""
}
>
deno 1.33.2

But not work when set proxy in vite.config.mts. It seems vite default proxy library not support using deno.