Skip to content

Commit

Permalink
docs: update jsdocs example for route utils (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes authored Feb 25, 2024
1 parent cb35dbe commit 2d10070
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/2.utils/98.advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ Allowed characters: horizontal tabs, spaces or visible ascii characters: https:/

Prefixes and executes a handler with a base path.

**Example:**

```ts
const app = createApp();
const router = createRouter();
const apiRouter = createRouter().get(
"/hello",
defineEventHandler((event) => {
return "Hello API!";
}),
);
router.use("/api/**", useBase("/api", apiRouter.handler));
app.use(router.handler);
```

<!-- /automd -->

## Cache
Expand Down
16 changes: 16 additions & 0 deletions src/utils/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import { eventHandler } from "../event";

/**
* Prefixes and executes a handler with a base path.
*
* @example
* const app = createApp();
* const router = createRouter();
*
* const apiRouter = createRouter().get(
* "/hello",
* defineEventHandler((event) => {
* return "Hello API!";
* }),
* );
*
* router.use("/api/**", useBase("/api", apiRouter.handler));
*
* app.use(router.handler);
*
* @param base The base path to prefix. When set to an empty string, the handler will be run as is.
* @param handler The event handler to use with the adapted path.
*/
Expand Down

0 comments on commit 2d10070

Please sign in to comment.