Skip to content

Commit

Permalink
fix middlewares instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Sep 1, 2024
1 parent d3e3fb3 commit c95c9ad
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,15 +677,20 @@ A middleware instance is created using `server.middleware()` and can then be use
var server = try httpz.Server(void).init(allocator, .{.port = 5882}, {});
// the middleware method takes the struct name and its configuration
const cors = server.middleware(middlewares.Cors, .{
const cors = try server.middleware(httpz.middleware.Cors, .{
.origin = "https://www.openmymind.net/",
});
// applies these middlewares to any following route definitions
router.middlewares = &.{cors};
// apply this middleware to all routes (unless the route
// explicitly opts out)
var router = server.router(.{.middlewares = .{cors}});
// and/or on a specific route (also available on a route group)
// or we could add middleware on a route-per-route bassis
router.get("/v1/users", .{.middlewares = &.{cors}});
// by default, middlewares on a route are appended to the global middlewares
// we can replace them instead by specifying a middleware_strategy
router.get("/v1/metrics", .{.middlewares = &.{cors}, .middleware_strategy = .replace});
```

## Cors
Expand Down

0 comments on commit c95c9ad

Please sign in to comment.