Expected Behavior
When constructing new Router({ prefix: '/api' }) and registering a root route with app.get('/', handler), the route should be reachable at the prefix path (/api and/or /api/). When the prefix accidentally ends with /, joining a child path should not produce a double slash.
Current Behavior
resolvePrefixedPath (packages/event-handler/src/http/utils.ts:334-346) ends with:
return `${prefix}${path}`.replace(/\/$/, '') as Path;
Two concrete failures:
resolvePrefixedPath('/', '/api') returns '/api' — the trailing slash is stripped. A handler registered at / under /api is unreachable from /api/; the request resolves to 404.
resolvePrefixedPath('/users', '/api/') returns '/api//users' — a literal double slash. Incoming requests to /api/users don't match the registered route id.
Code snippet
import { Router } from '@aws-lambda-powertools/event-handler/http';
const app = new Router({ prefix: '/api' });
app.get('/', () => ({ root: true }));
// Request to /api/ → 404 Not Found (expected: 200 with { root: true })
const app2 = new Router({ prefix: '/api/' });
app2.get('/users', () => ({ users: [] }));
// Internally registers GET:/api//users; request to /api/users → 404
Steps to Reproduce
- Construct a
Router with prefix: '/api' and register a handler at '/'.
- Resolve a request for
/api/.
- Observe
statusCode: 404.
- Repeat with
prefix: '/api/' and path: '/users'; observe the registered route id contains //.
- Or run the failing test:
npx vitest --run tests/unit/http/bugHunt.test.ts -t "Bug 5" from packages/event-handler/.
Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
(not applicable — bug is reproducible from a unit test)
Expected Behavior
When constructing
new Router({ prefix: '/api' })and registering a root route withapp.get('/', handler), the route should be reachable at the prefix path (/apiand/or/api/). When the prefix accidentally ends with/, joining a child path should not produce a double slash.Current Behavior
resolvePrefixedPath(packages/event-handler/src/http/utils.ts:334-346) ends with:Two concrete failures:
resolvePrefixedPath('/', '/api')returns'/api'— the trailing slash is stripped. A handler registered at/under/apiis unreachable from/api/; the request resolves to 404.resolvePrefixedPath('/users', '/api/')returns'/api//users'— a literal double slash. Incoming requests to/api/usersdon't match the registered route id.Code snippet
Steps to Reproduce
Routerwithprefix: '/api'and register a handler at'/'./api/.statusCode: 404.prefix: '/api/'andpath: '/users'; observe the registered route id contains//.npx vitest --run tests/unit/http/bugHunt.test.ts -t "Bug 5"frompackages/event-handler/.Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
(not applicable — bug is reproducible from a unit test)