vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.35k stars 348 forks source link

Using `redirects` with external URL crashes the server #1865

Closed inetol closed 2 weeks ago

inetol commented 2 months ago

Description

Replicable with both Bun and Node.js...

94 |     const urlModified = createUrlFromComponents(null, pathnameOriginal, searchOriginal, hashOriginal);
95 |     return { urlModified, origin };
96 | }
97 | function addUrlOrigin(url, origin) {
98 |     const { origin: originCurrent, pathnameOriginal, searchOriginal, hashOriginal } = parseUrl(url, '/');
99 |     assert(originCurrent === null);
         ^
error: [vike@0.4.195][Bug] You stumbled upon a Vike bug. Go to https://github.com/vikejs/vike/issues/new and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).
      at addUrlOrigin (/home/inetol/gitgud/vikejs-vike-unknown/node_modules/vike/dist/esm/utils/parseUrl-extras.js:99:5)
      at getPermanentRedirect (/home/inetol/gitgud/vikejs-vike-unknown/node_modules/vike/dist/esm/node/runtime/renderPage.js:378:25)
      at /home/inetol/gitgud/vikejs-vike-unknown/node_modules/vike/dist/esm/node/runtime/renderPage.js:160:30

Minimal reproduction: https://github.com/inetol/vikejs-vike-1865

brillout commented 2 months ago

Only replicable with Bun (1.1.27 used)...

It's most likely a Bun issue then, thus closing.

That said, PR welcome for a simple workaround. Have a look at the stack trace. The scope is relatively limited and, therefore, it could be relatively simple to get to the bottom of this.

inetol commented 3 weeks ago

It doesn't seem to be an issue unique to Bun because it is now failing with Node.js as well.

Generating with Bâti these 3 setups without other modifications, adding the corresponding redirect and going to /external it is possible to replicate the issue in all of them using dev mode:

Hono: https://stackblitz.com/edit/thxyoe-9ysctx?file=vite.config.ts Express: https://stackblitz.com/edit/wbpg9r-fhnqri?file=vite.config.ts H3: https://stackblitz.com/edit/g41jd2-bnhqu8?file=vite.config.ts

brillout commented 2 weeks ago

:+1: Can you publish the Express one to GitHub?

inetol commented 2 weeks ago

Sure https://github.com/inetol/vikejs-vike-1865

I have updated the instructions in the README

brillout commented 2 weeks ago

Fix pre-released as 0.4.199-commit-29f9afc.