Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain redirect scenarios result in TypeError: immutable #24

Closed
eliellis opened this issue Jan 26, 2025 · 1 comment
Closed

Certain redirect scenarios result in TypeError: immutable #24

eliellis opened this issue Jan 26, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@eliellis
Copy link

What version of Elysia is running?

1.2.10

What platform is your computer?

Darwin 24.1.0 arm64 arm

What steps can reproduce the bug?

Run the following:

import { Elysia } from "elysia";
import { node } from "@elysiajs/node";
import { cors } from "@elysiajs/cors";

const app = new Elysia({
  adapter: typeof Bun === "undefined" ? node() : undefined,
})
  .use(cors())
  .get("/home", () => {
    return "Home";
  })
  .onError(({ redirect }) => {
    return redirect("http://localhost:3000/home");
  })
  .onRequest(({ request, redirect }) => {
    if (new URL(request.url).pathname !== "/home") {
      return redirect("/home");
    }
  })
  .listen(3000);

const res = await fetch("http://localhost:3000/redirect-me", {
  redirect: "manual",
});

console.log("status", res.status);

await app.stop(true);

What is the expected behavior?

The above should print status 302. Running the same sample with bun run does print status 302.

What do you see instead?

node:internal/deps/undici/undici:8651
        throw new TypeError("immutable");
              ^

TypeError: immutable
    at appendHeader (node:internal/deps/undici/undici:8651:15)
    at _Headers.append (node:internal/deps/undici/undici:8854:16)
    at mergeResponseWithSetHeaders (file:///Users/eli/code/elysia-node-redirect-issue/node_modules/elysia/dist/adapter/web-standard/handler.mjs:185:24)
    at mapResponse (file:///Users/eli/code/elysia-node-redirect-issue/node_modules/@elysiajs/node/dist/index.mjs:240:18)
    at Elysia.eval [as handleError] (eval at composeErrorHandler (file:///Users/eli/code/elysia-node-redirect-issue/node_modules/elysia/dist/compose.mjs:1435:10), <anonymous>:19:53)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v23.6.1

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

yes

@eliellis eliellis added the bug Something isn't working label Jan 26, 2025
@SaltyAom
Copy link
Member

SaltyAom commented Feb 1, 2025

The redirect value is expected to be a full URL due to the Web Standard redirect.
We don't support partial URLs at the moment which is reported under #25.

Moving the issue all together with #25

@SaltyAom SaltyAom closed this as completed Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants