1

I want to log something on every incoming request and then I used the .any() method in the routing and placed the logger there. However, this ruined the 404 not found behaviour. Is there another way to do this sort of enter/exit methods properly?

ravenskater
  • 702
  • 1
  • 7
  • 20

1 Answers1

2

If you want to handle such “filter” like stuff, you should call req.next() - this will tell the server there is another handler. If nothing is found, 404 is returned as expected

Routing.builder()
  .any((req, res) -> {
    System.out.println(“Request: ” + req.path());
    req.next();
  })
  .get(“/”, (req, res) -> res.send(“Hello World”))
.build(); 
Tomas Langer
  • 451
  • 3
  • 5