CodeGenieApp / CodeGenieApp/serverless-express

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

Offen
#465 1 Kommentar 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
5.3k
Forks
676
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, die Verarbeitung von API Gateway V2-Ereignissen nachzuverfolgen, die rawPath an Express weiterleitet, wobei event.requestContext.stage und event.pathParameters.proxy als die im Issue beschriebenen Alternativen verwendet werden. Lege fest, wie das Entfernen des stage-Anteils und ein konfigurierbares Pfadpräfix bei Bereitstellungen mit benutzerdefinierter Domain und ohne benutzerdefinierte Domain funktionieren sollen, und überprüfe anschließend den weitergeleiteten Anfragepfad für jedes Szenario.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
aws, express, javascript, node.js
Bereich
api, backend, cloud
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.