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 can I use middleware in the server library? #960

Closed
graforlock opened this issue Dec 30, 2023 · 1 comment
Closed

How can I use middleware in the server library? #960

graforlock opened this issue Dec 30, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@graforlock
Copy link

I am struggling to see how can I use backend middleware using the connect server. For example, to automatically parse things like session cookies. At the moment I am doing it in every handler like this:

export default (router: ConnectRouter) =>
  router.service(MarketplaceService, {
    async getTask(opts: { taskId: string }, ctx) {
      const session = sessionService.getSession(ctx.requestHeader.get('cookie'));

      return await tasksUseCases.getTaskById(session.id, opts.taskId);
    },
}

But surely there must be a better way?

(I cannot use connect-web because those cookies are httpOnly)

@graforlock graforlock added the enhancement New feature or request label Dec 30, 2023
@srikrsna-buf
Copy link
Member

Hey! We don't yet have server side interceptors it is tracked in #527. But for the use case that you highlighted you can parse the cookie at the server(fastify/express) layer and add the parsed information to the context. This was added in v1.1.0. There's a similar example in the release notes

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

No branches or pull requests

2 participants