@farm.js/plugin 0.1.0-beta.106 → 0.1.0-beta.107
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/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,6 +16,12 @@ export declare function parseCookies(cookieHeader?: string): Record<string, stri
|
|
|
16
16
|
* Matching is by path segment, not raw string prefix: middleware at `/admin`
|
|
17
17
|
* covers `/admin` and everything under `/admin/`, but not sibling routes like
|
|
18
18
|
* `/administrator` or `/admin-public` that merely share a textual prefix.
|
|
19
|
+
*
|
|
20
|
+
* The request is compared as the router sees it: each segment decoded once and
|
|
21
|
+
* empty segments dropped. Comparing the raw pathname let `/api/%61dmin/users`,
|
|
22
|
+
* `/api//admin/users` and `//api/admin/users` skip middleware at `/api/admin`
|
|
23
|
+
* while the API router, which decodes segments and ignores empty ones, still
|
|
24
|
+
* served `/api/admin/users`.
|
|
19
25
|
*/
|
|
20
26
|
export declare function middlewareMatchesPath(pathname: string, middlewarePath: string): boolean;
|
|
21
27
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../../src/middleware/matching.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../../src/middleware/matching.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1E;AAUD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAkChG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { canonicalizeRequestPathSegments } from "@farm.js/core/middleware";
|
|
1
2
|
/**
|
|
2
3
|
* Parse cookies from a Cookie header.
|
|
3
4
|
*
|
|
@@ -34,13 +35,21 @@ function decodeCookieValue(value) {
|
|
|
34
35
|
* Matching is by path segment, not raw string prefix: middleware at `/admin`
|
|
35
36
|
* covers `/admin` and everything under `/admin/`, but not sibling routes like
|
|
36
37
|
* `/administrator` or `/admin-public` that merely share a textual prefix.
|
|
38
|
+
*
|
|
39
|
+
* The request is compared as the router sees it: each segment decoded once and
|
|
40
|
+
* empty segments dropped. Comparing the raw pathname let `/api/%61dmin/users`,
|
|
41
|
+
* `/api//admin/users` and `//api/admin/users` skip middleware at `/api/admin`
|
|
42
|
+
* while the API router, which decodes segments and ignores empty ones, still
|
|
43
|
+
* served `/api/admin/users`.
|
|
37
44
|
*/
|
|
38
45
|
export function middlewareMatchesPath(pathname, middlewarePath) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (pathname === middlewarePath)
|
|
46
|
+
const middlewareSegments = middlewarePath.split("/").filter(Boolean);
|
|
47
|
+
if (middlewareSegments.length === 0)
|
|
42
48
|
return true;
|
|
43
|
-
|
|
49
|
+
const requestSegments = canonicalizeRequestPathSegments(pathname);
|
|
50
|
+
if (requestSegments.length < middlewareSegments.length)
|
|
51
|
+
return false;
|
|
52
|
+
return middlewareSegments.every((segment, index) => requestSegments[index] === segment);
|
|
44
53
|
}
|
|
45
54
|
/**
|
|
46
55
|
* Serialize a cookie.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/plugin",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.107",
|
|
4
4
|
"description": "Official plugins for Farm.js framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Farm.js Team",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"nitro": "3.0.260903-beta",
|
|
63
63
|
"picocolors": "^1.0.0",
|
|
64
64
|
"rsc-html-stream": "^0.0.4",
|
|
65
|
-
"@farm.js/core": "0.1.0-beta.
|
|
65
|
+
"@farm.js/core": "0.1.0-beta.107"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/node": "^20.19.21",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"react-dom": "19.2.8",
|
|
84
84
|
"react-server-dom-webpack": "19.2.8",
|
|
85
85
|
"vite": ">=6.0.0",
|
|
86
|
-
"@farm.js/core": "0.1.0-beta.
|
|
86
|
+
"@farm.js/core": "0.1.0-beta.107"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
89
89
|
"@vitejs/plugin-rsc": {
|