Closed juv closed 3 months ago
What you have is:
path("/outer-path", () -> {
path("/inner-path", () -> {
before(ctx -> LOGGER.info("before of /inner-path")); // before everything under "/inner-path/*"
get(ctx -> ctx.result("this is not executed"));
get("/{some-input-id}", ctx -> ctx.result("this is not executed either 2"));
path("/a-bit-more-specific", () -> { // before everything under "/inner-path/a-bit-more-specific/*"
before(ctx -> LOGGER.info("before of /inner-path/a-bit-more-specific"));
get("/hi", ctx -> ctx.result("hi"));
});
});
});
If you look at it like this, do you still only expect 1 before handler to fire?
What you have is:
path("/outer-path", () -> { path("/inner-path", () -> { before(ctx -> LOGGER.info("before of /inner-path")); // before everything under "/inner-path/*" get(ctx -> ctx.result("this is not executed")); get("/{some-input-id}", ctx -> ctx.result("this is not executed either 2")); path("/a-bit-more-specific", () -> { // before everything under "/inner-path/a-bit-more-specific/*" before(ctx -> LOGGER.info("before of /inner-path/a-bit-more-specific")); get("/hi", ctx -> ctx.result("hi")); }); }); });
If you look at it like this, do you still only expect 1 before handler to fire?
Hi, absolutely not. Thanks for clarifying that these separated endpoint groups will be merged and are not treated as individual ones after all and this is expected.
Actual behavior (the bug) When configuring routes like this:
and creating a
GET
request to/outer-path/inner-path/a-bit-more-specific/hi
will execute bothbefore
handlers and return the stringhi
.Mixing both
/{path-params}
paths and/static
paths inside of the same endpoint group sometimes creates unwanted effects. Therefore I tried to split the handlers up into two endpoint groups but thebefore
handlers are still executed even when the request itself would not always match a "real http" handler in the endpoint group.Expected behavior Only the
before
handler of endpoint group/inner-path/a-bit-more-specific
is executed, similar to how the request is only triggering theget("/hi", ctx -> ctx.result("hi"));
handler after all.To Reproduce use
curl http://localhost:{your javalin port}/outer-path/inner-path/a-bit-more-specific/hi
Additional context Console log: