Skip to content

Middlewares: How to apply only to existing routes #49

Answered by mathieucarbou
DRSDavidSoft asked this question in Q&A
Discussion options

You must be logged in to vote

@DRSDavidSoft : I have raised a PR here: #50 to:

  • Allow to skip global server middleware on any handler
  • Allow to access the catch-all handler to add middlewares on it

I added an example showing how to use that: https://github.com/ESP32Async/ESPAsyncWebServer/blob/feat/skip-server-middleware/examples/SkipServerMiddleware/SkipServerMiddleware.ino

  // we apply auth middleware to the server globally
  server.addMiddleware(&basicAuth);

  // protected endpoint: requires basic authentication
  // curl -v -u admin:admin  http://192.168.4.1/
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send(200, "text/plain", "Hello, world!");
  });

  // we skip all global middl…

Replies: 3 comments 12 replies

Comment options

You must be logged in to vote
7 replies
@DRSDavidSoft
Comment options

@mathieucarbou
Comment options

@mathieucarbou
Comment options

@DRSDavidSoft
Comment options

@DRSDavidSoft
Comment options

Comment options

You must be logged in to vote
2 replies
@mathieucarbou
Comment options

@DRSDavidSoft
Comment options

Comment options

You must be logged in to vote
3 replies
@DRSDavidSoft
Comment options

@DRSDavidSoft
Comment options

@mathieucarbou
Comment options

Answer selected by DRSDavidSoft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants