orpc-file-based-router 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,9 @@ structure, similar to Next.js, express-file-routing
|
|
|
14
14
|
> ⚠️ **IMPORTANT:** At this time, the plugin's functionality is only guaranteed
|
|
15
15
|
> in nodejs runtime
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Quickstart
|
|
18
|
+
|
|
19
|
+
0. If you're new to oRPC, read the [oRPC documentation](https://orpc.unnoq.com). Install and configure a basic oRPC server
|
|
18
20
|
|
|
19
21
|
1. Install package
|
|
20
22
|
|
|
@@ -45,7 +47,7 @@ src/routes
|
|
|
45
47
|
└── sse.ts
|
|
46
48
|
```
|
|
47
49
|
|
|
48
|
-
3. Each file should export
|
|
50
|
+
3. Each file should export an oRPC function
|
|
49
51
|
|
|
50
52
|
4. Simply replace router in your handlers with the result of the `createRouter`
|
|
51
53
|
function:
|
|
@@ -58,11 +60,23 @@ const routesDir = new URL("./routes", import.meta.url).pathname;
|
|
|
58
60
|
const router = await createRouter(routesDir);
|
|
59
61
|
|
|
60
62
|
const handler = new RPCHandler(router);
|
|
63
|
+
|
|
61
64
|
```
|
|
65
|
+
> **Note:** If your environment doesn't support top-level await, wrap your server startup code in an async function:
|
|
66
|
+
> ```typescript
|
|
67
|
+
> async function startServer() {
|
|
68
|
+
> const router = await createRouter(routesDir);
|
|
69
|
+
> const handler = new RPCHandler(router);
|
|
70
|
+
> // ... start your server
|
|
71
|
+
> }
|
|
72
|
+
> startServer();
|
|
73
|
+
> ```
|
|
74
|
+
|
|
75
|
+
## Type-Safe Client Configuration (Optional)
|
|
62
76
|
|
|
63
|
-
|
|
77
|
+
If you plan to use [oRPC client](https://orpc.unnoq.com/docs/client/client-side), you can set up automatic configuration generation, which can be used for client typing.
|
|
64
78
|
|
|
65
|
-
1.
|
|
79
|
+
1. Add the following code to your main server file (e.g., `server.ts` or `main.ts`). This will automatically regenerate the router configuration each time your server starts:
|
|
66
80
|
|
|
67
81
|
```typescript
|
|
68
82
|
import { generateRouter } from "orpc-file-based-router";
|
|
@@ -72,7 +86,7 @@ const outputFile = new URL("./router.ts", import.meta.url).pathname;
|
|
|
72
86
|
generateRouter(routesDir, outputFile);
|
|
73
87
|
```
|
|
74
88
|
|
|
75
|
-
2. Generated
|
|
89
|
+
2. Generated router is ready to use in client:
|
|
76
90
|
|
|
77
91
|
```typescript
|
|
78
92
|
// router.ts
|
package/package.json
CHANGED