Skip to content

Commit

Permalink
Merge pull request #247 from alessandrojcm/api-router-app-params
Browse files Browse the repository at this point in the history
feat: add params to h3 event object for api router
  • Loading branch information
nksaraf committed Mar 10, 2024
2 parents 618149b + d79b90f commit f354348
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-chairs-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vinxi/router": patch
---

feat: add params to h3 event object for api router
7 changes: 5 additions & 2 deletions packages/vinxi-router/api-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const routes = [
...route,
handler: async (event, params) => {
const mod = await route.$handler.import();
return await mod.default(event, params);
event.context['params'] = params
return await mod.default(event);
},
})),
];
Expand Down Expand Up @@ -35,7 +36,9 @@ function createRouter(routes) {
for (let i = 0; i < route.keys.length; i++) {
params[route.keys[i].name] = match[i + 1];
}
return await route.handler(event, params);
// add params to context object
event.context['params'] = params
return await route.handler(event);
}
}

Expand Down

0 comments on commit f354348

Please sign in to comment.