rouzer 1.0.0-beta.13 → 1.0.0-beta.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/dist/auth.d.ts +1 -0
- package/dist/auth.js +1 -0
- package/dist/server/router.js +6 -5
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/readme.md +39 -0
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/server/router.js
CHANGED
|
@@ -24,8 +24,9 @@ export function createRouter(config) {
|
|
|
24
24
|
return (handlers) => middlewares.use(async function (context) {
|
|
25
25
|
const request = context.request;
|
|
26
26
|
const origin = request.headers.get('Origin');
|
|
27
|
-
if (
|
|
28
|
-
|
|
27
|
+
if (origin &&
|
|
28
|
+
allowOrigins &&
|
|
29
|
+
!allowOrigins.some(pattern => pattern.test(origin))) {
|
|
29
30
|
return new Response(null, { status: 403 });
|
|
30
31
|
}
|
|
31
32
|
const url = (context.url ??= new URL(request.url));
|
|
@@ -60,9 +61,9 @@ export function createRouter(config) {
|
|
|
60
61
|
},
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if (origin) {
|
|
65
|
+
context.setHeader('Access-Control-Allow-Origin', origin);
|
|
66
|
+
}
|
|
66
67
|
if (route.path) {
|
|
67
68
|
const error = parsePathParams(context, enableStringParsing(route.path), match.params);
|
|
68
69
|
if (error) {
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -39,6 +39,17 @@ The following request parts can be validated with Zod:
|
|
|
39
39
|
|
|
40
40
|
Zod validation happens on both the server and client.
|
|
41
41
|
|
|
42
|
+
## Route URL patterns
|
|
43
|
+
|
|
44
|
+
Rouzer uses `@remix-run/route-pattern` for matching and generation. Patterns can include:
|
|
45
|
+
|
|
46
|
+
- Pathname-only patterns like `blog/:slug` (default).
|
|
47
|
+
- Full URLs with protocol/hostname/port like `https://:store.shopify.com/orders`.
|
|
48
|
+
- Dynamic segments with `:param` names (valid JS identifiers), including multiple params in one segment like `v:major.:minor`.
|
|
49
|
+
- Optional segments wrapped in parentheses, which can be nested like `api(/v:major(.:minor))`.
|
|
50
|
+
- Wildcards with `*name` (captured) or `*` (uncaptured) for multi-segment paths like `assets/*path` or `files/*`.
|
|
51
|
+
- Query matching with `?` to require parameters or exact values like `search?q` or `search?q=routing`.
|
|
52
|
+
|
|
42
53
|
## Server router
|
|
43
54
|
|
|
44
55
|
```ts
|
|
@@ -66,6 +77,34 @@ export const handler = createRouter({
|
|
|
66
77
|
})
|
|
67
78
|
```
|
|
68
79
|
|
|
80
|
+
## Router options
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
export const handler = createRouter({
|
|
84
|
+
routes,
|
|
85
|
+
middlewares,
|
|
86
|
+
basePath: 'api/',
|
|
87
|
+
cors: {
|
|
88
|
+
allowOrigins: ['example.net', 'https://*.example.com', '*://localhost:3000'],
|
|
89
|
+
},
|
|
90
|
+
debug: process.env.NODE_ENV === 'development',
|
|
91
|
+
})({
|
|
92
|
+
helloRoute: {
|
|
93
|
+
GET(ctx) {
|
|
94
|
+
const message = `Hello, ${ctx.path.name}${ctx.query.excited ? '!' : '.'}`
|
|
95
|
+
return { message }
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- `basePath` is prepended to every route (leading/trailing slashes are trimmed).
|
|
102
|
+
- CORS preflight (`OPTIONS`) is handled automatically for matched routes.
|
|
103
|
+
- `cors.allowOrigins` restricts preflight requests to a list of origins (default is to allow any origin).
|
|
104
|
+
- Wildcards are supported for protocol and subdomain; the protocol is optional and defaults to `https`.
|
|
105
|
+
- If you rely on `Cookie` or `Authorization` request headers, you must set
|
|
106
|
+
`Access-Control-Allow-Credentials` in your handler.
|
|
107
|
+
|
|
69
108
|
## Client wrapper
|
|
70
109
|
|
|
71
110
|
```ts
|