CodeGenieApp / CodeGenieApp/serverless-express

Request path should not include the stage name with API Gateway V2 event source

Open
#465 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.3k
Forks
676
PR merge metrics
No merged PRs in 30d

Description

AWS always includes the stage name in the request path of API Gateway V2 events, even when using a custom domain and an ApiMapping.

**Without a custom domain**
* Invoke URL: `https://{apiId}.execute-api.{region}.amazonaws.com/{stageName}/foo`
* API Gateway V2 event's `rawPath`: `/{stageName}/foo`
* Path forwarded to the application: `/{stageName}/foo`

**With a custom domain / ApiMapping using an ApiMappingKey**
* Invoke URL: `https://{customDomain}/{ApiMappingKey}/foo`
* API Gateway V2 event's `rawPath`: `/{stageName}/foo`
* Path forwarded to the application: `/{stageName}/foo`

This means there is no reliable way to determine the real path entered in the user's address bar (stage name is not relevant when using a custom domain with ApiMapping, and ApiMappingKey is never forwarded in the event) :/ In the end, I think `serverless-express` should not include the stage name in the request path forwarded to `express` and allow to set a custom path prefix for all requests. It would make it possible to have a valid path for all deployment scenarios with a relatively minimal configuration setup.

There are multiple ways to do this, a reliable one being to trim the stage name from the path using `event.requestContext.stage`. You could also use `event.pathParameters.proxy` to set the path, but the user might not have used the `{proxy+}` proxy resource for his API.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.