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

Middleware cannot access context.params when nested #435

Open
N8Brooks opened this issue Dec 5, 2021 · 0 comments
Open

Middleware cannot access context.params when nested #435

N8Brooks opened this issue Dec 5, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@N8Brooks
Copy link

N8Brooks commented Dec 5, 2021

For example some slight modifications for the example in the README

import { Application, Router } from "https://deno.land/x/oak/mod.ts";

const posts = new Router()
  .use(async (ctx, next) => {
    console.log(ctx.params); // {}
    await next();
  })
  .get("/", (ctx) => {
    console.log(ctx.params); // {forumId: string}
  });

const forums = new Router()
  .use("/forums/:forumId/posts", posts.routes(), posts.allowedMethods());

await new Application()
  .use(forums.routes())
  .listen({ port: 8000 });

Actual Behaviour

  • When accessing ctx.params from the middleware it is an empty object. Since it is available at all I would expect the params to exist.

Expected Behaviour

  • When accessing ctx.params from the middleware it has an object containing the forumId property. This is different than the ctx.params in the routes.

Details

  • Oak v10.0.0
  • Not sure if this is a bug/feature request/expected behaviour.
  • This functionality could be useful if there is some common behaviour applied to forumId across the nested routes.
@kitsonk kitsonk added the bug Something isn't working label Dec 19, 2021
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