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

Nested async plugins aren't awaited #945

Open
bogeychan opened this issue Dec 18, 2024 · 1 comment · May be fixed by #975
Open

Nested async plugins aren't awaited #945

bogeychan opened this issue Dec 18, 2024 · 1 comment · May be fixed by #975
Labels
bug Something isn't working

Comments

@bogeychan
Copy link
Contributor

What version of Elysia is running?

1.1.26

What platform is your computer?

WSL Ubuntu

What steps can reproduce the bug?

// index.ts
import { Elysia } from "elysia";

const yay = async () => {
  await Bun.sleep(2_000);

  return new Elysia({ name: "yay" }).get("/yay", "yay");
};

const wrapper = new Elysia({ name: "wrapper" }).use(yay());

// await wrapper.modules; <- this is missing inside elysia

const app = new Elysia().use(wrapper).listen(3000);

console.log(`${app.server!.url}`);

Open: http://localhost:3000/yay

What is the expected behavior?

Browser output:

yay

What do you see instead?

Brower output:

NOT_FOUND

Additional information

await wrapper.modules; <- this is missing inside elysia

relates to elysiajs/elysia-static#23

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

yes

@bogeychan bogeychan added the bug Something isn't working label Dec 18, 2024
@bogeychan
Copy link
Contributor Author

bogeychan commented Dec 18, 2024

Here's a test case:

// test.test.ts
import { test, expect } from "bun:test";
import { Elysia } from "elysia";

test("Await nested async plugin", async () => {
  const yay = async () => {
    await Bun.sleep(2_000);

    return new Elysia({ name: "yay" }).get("/yay", "yay");
  };

  const wrapper = new Elysia({ name: "wrapper" }).use(yay());

  // await wrapper.modules; <- this is missing inside elysia

  const app = new Elysia().use(wrapper);

  await app.modules;

  const response = await app.handle(new Request(`http://localhost/yay`));

  expect(response.status).toBe(200);
});

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

Successfully merging a pull request may close this issue.

1 participant