Skip to content

Commit

Permalink
Add a getOrHead() matcher to the router for matching GET or `HEAD…
Browse files Browse the repository at this point in the history
…` requests with a single configuration definition (#103)
  • Loading branch information
mangs authored Sep 7, 2024
1 parent b1e8f88 commit a94f5f7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.32.0

- Add a `getOrHead()` matcher to the router for matching `GET` or `HEAD` requests with a single configuration definition

## 2.31.2

- Improve request logging in the development server by using `Request` cloning
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mangs/bun-utils",
"version": "2.31.2",
"version": "2.32.0",
"author": "Eric L. Goldstein",
"description": "Useful utils for your Bun projects",
"engines": {
Expand Down
14 changes: 14 additions & 0 deletions src/routerUtils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ class Router {
return this.#handleMethod(path, routeHandler, 'GET');
}

/**
* Register a route handler that matches the `GET` or `HEAD` HTTP request methods.
* @param path A path-like string that will be used to match against the incoming request's path.
* @param routeHandler The function that will execute if this route handler is matched. Eagerly-loaded route handlers pass functions in directly; lazy-loaded ones pass in an object whose key corresponds to a module's named export or `'default'` for default export.
* @returns A reference to the instantiated instance (`this`) so route handler definitions can be chained.
* @example
* ```ts
* router.getOrHead('/*', { pageRoute: () => import('./routes/pageRoute.mts') })
* ```
*/
getOrHead(path: string, routeHandler: RouteHandler) {
return this.#handleMethod(path, routeHandler, 'GET').#handleMethod(path, routeHandler, 'HEAD');
}

/**
* Register a route handler that matches the `HEAD` HTTP request method.
* @param path A path-like string that will be used to match against the incoming request's path.
Expand Down

0 comments on commit a94f5f7

Please sign in to comment.