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

How to hook or add tranditional middleware ? #315

Closed
wenerme opened this issue Nov 16, 2023 · 3 comments · May be fixed by #318
Closed

How to hook or add tranditional middleware ? #315

wenerme opened this issue Nov 16, 2023 · 3 comments · May be fixed by #318

Comments

@wenerme
Copy link

wenerme commented Nov 16, 2023

I want to

{
  const next = app.fetch;
  app.fetch = (req) => {
    console.log(`Hook middleware`);
    return runContext(() => next(req));
  };
}

app.listen(8080, (server) => {
  log.log(`Listening on ${server.url}`);
});

but this not works, maybe trace+handle can do this, but I think trace is not for this.

@SaltyAom
Copy link
Member

@wenerme
Copy link
Author

wenerme commented Nov 16, 2023

@SaltyAom sorry if I miss anything, I don't find any life cycle can do this, so I tried to read the code, I want to warp this handle

let response = handle(context)
or earlyer, guard may need the context access(e.g. db).

@wenerme
Copy link
Author

wenerme commented Nov 27, 2023

Found a workaround

  app.onStart(({ app }) => {
    app.server?.reload({
      fetch: async (req) => {
        console.log(`Hook by Reload`);
        return runContext(() => app.fetch(req));
      },
    });
  });

@SaltyAom there is no hook for wrap handle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants