bxo 0.0.5-dev.78 → 0.0.5-dev.79
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/example/url-encoding-example.ts +12 -0
- package/package.json +1 -1
- package/src/index.ts +5 -4
- package/test-url-encoding.ts +19 -0
|
@@ -31,6 +31,16 @@ async function main() {
|
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
+
// Route with multiple path parameters including URL-encoded spaces
|
|
35
|
+
app.get("/api/resources/:resourceType/:id", (ctx) => {
|
|
36
|
+
return ctx.json({
|
|
37
|
+
message: `Found resource: ${ctx.params.resourceType} with ID: ${ctx.params.id}`,
|
|
38
|
+
path: ctx.request.url,
|
|
39
|
+
pathname: new URL(ctx.request.url).pathname,
|
|
40
|
+
params: ctx.params
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
34
44
|
// Test route to show the difference
|
|
35
45
|
app.get("/test", (ctx) => {
|
|
36
46
|
return ctx.text(`
|
|
@@ -46,12 +56,14 @@ async function main() {
|
|
|
46
56
|
<li><a href="/api/resources/Workspace Item">/api/resources/Workspace Item</a> (with space)</li>
|
|
47
57
|
<li><a href="/api/resources/Workspace%20Item">/api/resources/Workspace%20Item</a> (URL encoded)</li>
|
|
48
58
|
<li><a href="/api/resources/My%20Resource">/api/resources/My%20Resource</a> (URL encoded with params)</li>
|
|
59
|
+
<li><a href="/api/resources/Doctype%20Permission/01992af8-1c69-7000-9219-9b83c2feb2d6">/api/resources/Doctype%20Permission/01992af8-1c69-7000-9219-9b83c2feb2d6</a> (URL encoded with ID)</li>
|
|
49
60
|
</ul>
|
|
50
61
|
|
|
51
62
|
<h2>Test with JavaScript fetch:</h2>
|
|
52
63
|
<button onclick="testFetch('/api/resources/Workspace Item')">Test with space</button>
|
|
53
64
|
<button onclick="testFetch('/api/resources/Workspace%20Item')">Test URL encoded</button>
|
|
54
65
|
<button onclick="testFetch('/api/resources/My%20Resource')">Test with params</button>
|
|
66
|
+
<button onclick="testFetch('/api/resources/Doctype%20Permission/01992af8-1c69-7000-9219-9b83c2feb2d6')">Test with ID</button>
|
|
55
67
|
|
|
56
68
|
<div id="result"></div>
|
|
57
69
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -531,7 +531,7 @@ export default class BXO {
|
|
|
531
531
|
return this;
|
|
532
532
|
}
|
|
533
533
|
|
|
534
|
-
private async dispatch(route: InternalRoute, req: Request): Promise<Response> {
|
|
534
|
+
private async dispatch(route: InternalRoute, req: Request, pathname?: string): Promise<Response> {
|
|
535
535
|
// Run beforeRequest hooks
|
|
536
536
|
for (const hook of this.beforeRequestHooks) {
|
|
537
537
|
try {
|
|
@@ -559,7 +559,8 @@ export default class BXO {
|
|
|
559
559
|
}
|
|
560
560
|
|
|
561
561
|
const url = new URL(req.url);
|
|
562
|
-
const
|
|
562
|
+
const actualPathname = pathname || url.pathname;
|
|
563
|
+
const params = this.extractParams(route, actualPathname);
|
|
563
564
|
let queryObj: any;
|
|
564
565
|
let bodyObj: any = undefined;
|
|
565
566
|
const cookieObj = parseCookies(req.headers.get("cookie"));
|
|
@@ -814,7 +815,7 @@ export default class BXO {
|
|
|
814
815
|
if (r.matcher === null) continue; // exact paths handled above
|
|
815
816
|
if (r.method !== method && r.method !== "DEFAULT") continue;
|
|
816
817
|
const m = url.pathname.match(r.matcher);
|
|
817
|
-
if (m) return this.dispatch(r, req);
|
|
818
|
+
if (m) return this.dispatch(r, req, url.pathname);
|
|
818
819
|
}
|
|
819
820
|
|
|
820
821
|
// 2.5) Try URL-decoded pathname for pattern matches
|
|
@@ -823,7 +824,7 @@ export default class BXO {
|
|
|
823
824
|
if (r.matcher === null) continue; // exact paths handled above
|
|
824
825
|
if (r.method !== method && r.method !== "DEFAULT") continue;
|
|
825
826
|
const m = decodedPathname.match(r.matcher);
|
|
826
|
-
if (m) return this.dispatch(r, req);
|
|
827
|
+
if (m) return this.dispatch(r, req, decodedPathname);
|
|
827
828
|
}
|
|
828
829
|
}
|
|
829
830
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import BXO from "./src";
|
|
2
|
+
|
|
3
|
+
const app = new BXO({ serve: { port: 3001 } });
|
|
4
|
+
|
|
5
|
+
// Test the exact scenario you mentioned
|
|
6
|
+
app.get("/api/resources/:resourceType/:id", (ctx) => {
|
|
7
|
+
return ctx.json({
|
|
8
|
+
message: "Success!",
|
|
9
|
+
resourceType: ctx.params.resourceType,
|
|
10
|
+
id: ctx.params.id,
|
|
11
|
+
allParams: ctx.params,
|
|
12
|
+
url: ctx.request.url,
|
|
13
|
+
pathname: new URL(ctx.request.url).pathname
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
app.start();
|
|
18
|
+
console.log(`Test server running on http://localhost:${app.server?.port}`);
|
|
19
|
+
console.log(`Test URL: http://localhost:${app.server?.port}/api/resources/Doctype%20Permission/01992af8-1c69-7000-9219-9b83c2feb2d6`);
|