Skip to content

Commit 1bb52fa

Browse files
committed
feat: createHonoRouter to core pkg
1 parent c1c3c24 commit 1bb52fa

File tree

25 files changed

+270
-416
lines changed

25 files changed

+270
-416
lines changed

apps/website/docs/aws/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ npm i @storybooker/aws
1212

1313
### Hosting
1414

15-
- [AWS Lambda + API Gateway](lambda)
15+
Refer Hono docs for deployment instructions: https://hono.dev/docs/getting-started/aws-lambda
16+
17+
The hono app-router should be created using the `createHonoRouter` function from the [`@storybooker/core`](../core) package.
1618

1719
### Database
1820

apps/website/docs/aws/lambda.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

apps/website/docs/core/bun.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@ tags:
55

66
# Bun
77

8-
Run following with `bun server.ts`
8+
Run following with `bun run --hot server.ts`
9+
10+
> Refer Hono docs: https://hono.dev/docs/getting-started/bun
911
1012
```ts
1113
// server.ts
1214

13-
import {
14-
createRequestHandler,
15-
type RequestHandlerOptions,
16-
} from "@storybooker/core";
15+
import { createHonoRouter } from "@storybooker/core";
1716
import {
1817
LocalFileDatabase,
1918
LocalFileStorage,
2019
} from "@storybooker/core/adapters";
2120
import { createBasicUIAdapter } from "@storybooker/ui";
2221

23-
// Create StoryBooker router handler
24-
const handler = createRequestHandler({
22+
// Create StoryBooker router
23+
const router = createHonoRouter({
2524
// provide a supported database service adapter
2625
database: new LocalFileDatabase(),
2726
// provide a supported storage service adapter
@@ -30,5 +29,8 @@ const handler = createRequestHandler({
3029
ui: createBasicUIAdapter(),
3130
});
3231

33-
Bun.serve({ fetch: handler });
32+
export default {
33+
fetch: router.fetch,
34+
port: 8000,
35+
};
3436
```

apps/website/docs/core/deno.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ Run following with `deno serve -REW server.ts`
99

1010
> Note: You can change permissions based on your adapter choice.
1111
12+
> Refer Hono docs: https://hono.dev/docs/getting-started/deno
13+
1214
```ts
1315
// server.ts
1416

15-
import {
16-
createRequestHandler,
17-
type RequestHandlerOptions,
18-
} from "npm:@storybooker/core";
17+
import { createHonoRouter } from "jsr:@storybooker/core";
1918
import {
2019
LocalFileDatabase,
2120
LocalFileStorage,
22-
} from "npm:@storybooker/core/adapters";
21+
} from "jsr:@storybooker/core/adapters";
2322
import { createBasicUIAdapter } from "npm:@storybooker/ui";
2423

25-
// Create StoryBooker router handler
26-
const handler = createRequestHandler({
24+
// Create StoryBooker router
25+
const router = createHonoRouter({
2726
// provide a supported database service adapter
2827
database: new LocalFileDatabase(),
2928
// provide a supported storage service adapter
@@ -32,5 +31,5 @@ const handler = createRequestHandler({
3231
ui: createBasicUIAdapter(),
3332
});
3433

35-
export default { fetch: handler };
34+
export default router;
3635
```

apps/website/docs/core/index.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ npm i @storybooker/core
1717

1818
## API
1919

20-
### `createRequestHandler`
20+
### `createHonoRouter`
2121

22-
> [API Docs](https://jsr.io/@storybooker/core/doc/~/createRequestHandler)
22+
> [API Docs](https://jsr.io/@storybooker/core/doc/~/createHonoRouter)
2323
24-
Callback to create a request-handler based on provided options.
24+
Callback to create a Hono router that can be used as a request handler.
2525

26-
The request handler takes Standard Request and returns a Response asynchronously.
26+
The Hono router can be deployed to any platform that supports Hono framework.
2727

28-
[Read more about options](./request-options)
28+
[Read more about options](./router-options)
2929

3030
### `createPurgeHandler`
3131

@@ -56,3 +56,4 @@ A simple storage adapter that uses local folder to store files. Defaults to curr
5656
- [NodeJS](node)
5757
- [Deno](deno)
5858
- [Bun](bun)
59+
- Others: Refer [Hono docs](https://hono.dev/docs/getting-started/basic)

apps/website/docs/core/node.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ tags:
66

77
# NodeJS
88

9+
> Refer Hono docs: https://hono.dev/docs/getting-started/nodejs
10+
911
Run following with `node server.mjs`
1012

1113
```js
1214
// @ts-check
1315
// server.mjs
1416

15-
import { createServer } from "node:http";
16-
import { createRequestListener } from "@remix-run/node-fetch-server";
17-
import { createRequestHandler } from "@storybooker/core";
17+
import { serve } from "@hono/node-server";
18+
import { createHonoRouter } from "@storybooker/core";
1819
import {
1920
LocalFileDatabase,
2021
LocalFileStorage,
2122
} from "@storybooker/core/adapters";
2223
import { createBasicUIAdapter } from "npm:@storybooker/ui";
2324

24-
// Create StoryBooker router handler
25-
const handler = createRequestHandler({
25+
// Create StoryBooker Hono router
26+
const router = createHonoRouter({
2627
// provide a supported database service adapter
2728
database: new LocalFileDatabase(),
2829
// provide a supported storage service adapter
@@ -31,10 +32,6 @@ const handler = createRequestHandler({
3132
ui: createBasicUIAdapter(),
3233
});
3334

34-
// Create a standard Node.js server
35-
const server = createServer(createRequestListener(handler));
36-
37-
server.listen(8000, () => {
38-
console.log("Server running at http://localhost:8000");
39-
});
35+
// Create a Node.js server
36+
serve(router);
4037
```
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ tags:
44
- api
55
---
66

7-
# Request Handler Options
7+
# Router Options
88

9-
When creating a request handler using `createRequestHandler` (or a wrapper like `registerStoryBookerRouter` in Azure), you have to pass an options object which contain various service adapters and other options.
9+
When creating a request handler using `createHonoRouter` (or a wrapper like `registerStoryBookerRouter` in Azure), you have to pass an options object which contain various service adapters and other options.
1010

1111
```ts
1212
{
@@ -30,3 +30,21 @@ When creating a request handler using `createRequestHandler` (or a wrapper like
3030
config?: RequestHandlerConfigOptions;
3131
}
3232
```
33+
34+
## Config Options
35+
36+
The `config` object can contain additional custom options to be passed to the request handler. Some of the common options include:
37+
38+
### Middlewares
39+
40+
You can pass an array of middlewares to be used by the request handler. These middlewares should be compatible with the Hono framework.
41+
42+
```ts
43+
import { logger } from "hono/logger";
44+
45+
const config = {
46+
middlewares: [logger()],
47+
};
48+
```
49+
50+
Any middlewares provided by Hono can also be used here. Refer to the [Hono documentation](https://hono.dev/docs/guides/middleware) for more details.

apps/website/docs/gcp/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ npm i @storybooker/gcp
1212

1313
### Hosting
1414

15-
Currently no hosting adapter available for GCP. Though you can use GCP's App Engine or Cloud Run to host your StoryBooker application.
15+
Refer Hono docs for deployment instructions: https://hono.dev/docs/getting-started/google-cloud-run
1616

17-
To convert Express app request and response to StoryBooker compatible request and response, you can use the [`@remix-run/node-fetch-server`](https://npm.im/@remix-run/node-fetch-server) package with [`@storybooker/core`](../core).
17+
The hono app-router should be created using the `createHonoRouter` function from the [`@storybooker/core`](../core) package.
1818

1919
### Database
2020

apps/website/docs/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ StoryBooker is composed of 3 main parts:
1414

1515
The router is the core of StoryBooker. It is responsible for routing requests to the page/api and using the appropriate adapter to render the response.
1616

17-
The entire router is maintained in the [`@storybooker/core`](./core) package. The package is used to create a router-handler that takes a WebRequest and returns a WebResponse. The router is framework agnostic and can be used in any server environment that supports NodeJS api (NodeJS, Deno, Bun, etc.).
17+
The entire router is maintained in the [`@storybooker/core`](./core) package. The package is used to create a Hono app-router. The router is framework agnostic and can be used in any server environment that supports NodeJS api (NodeJS, Deno, Bun, etc.).
1818

1919
## Adapters
2020

@@ -24,10 +24,11 @@ The adapters are maintained in their respective packages and can be mixed and ma
2424

2525
The Adapters implement following services:
2626

27-
- Hosting: Responsible for serving the StoryBooker application. Examples: Azure Functions, AWS Lambda, etc.
2827
- Storage: Responsible for storing StoryBooker assets. Examples: Azure Blob Storage, AWS S3, etc.
2928
- Database: Responsible for managing StoryBooker data. Examples: Azure CosmosDB, AWS DynamoDB, etc.
3029
- Auth: Responsible for authenticating users. Examples: Azure EasyAuth, etc.
30+
- Logger: Responsible for logging events and errors. Examples: Azure Application Insights, AWS CloudWatch, etc.
31+
- UI: Responsible for providing HTML UI for GET routes. Without it, the service is headless only.
3132

3233
## CLI
3334

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"label": "Redis"
3+
}

0 commit comments

Comments
 (0)