Skip to content

Commit 8a07b69

Browse files
authored
fix: hono bff params order (#7232)
1 parent 78f1e19 commit 8a07b69

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

.changeset/itchy-memes-yell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modern-js/plugin-bff': patch
3+
---
4+
5+
fix: hono bff params order
6+
fix: 修复 hono 运行是框架获取 params 顺序问题

packages/cli/plugin-bff/src/utils/createHonoRoutes.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ export const createHonoHandler = (handler: Handler) => {
8181
throw error;
8282
}
8383
} else {
84-
const args = Object.values(input.params).concat(input);
84+
const routePath = c.req.routePath;
85+
const paramNames = routePath.match(/:\w+/g)?.map(s => s.slice(1)) || [];
86+
const params = Object.fromEntries(
87+
paramNames.map(name => [name, input.params[name]]),
88+
);
89+
const args = Object.values(params).concat(input);
90+
8591
try {
8692
const body = await handler(...args);
8793
if (c.finalized) {

pnpm-lock.yaml

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)