Omit base path mapping from the path in a proxied request #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, I'd like to say thank you @tj for your work!
I have been using
apex/gateway
for last few days while I was taking care of moving serverfull to serverless API. I have noticed two things, for which I've addressed fixes in this PR submission:addr string
which was passed as a parameter toListenAndServe
but I haven't noticed any usage of this variable.execute-api
API endpoints.Explanation of problem (2): Payload which you can receive via
execute-api
and this on your custom domain name with Base Path Mapping set is not consistent. Let/v2
will be ourBASE_PATH
, and also let/
(ListItems
) and/{id}
(GetItem
) routes be registered in API Gateway andhttp.Handler
. If you will callexecute-api
withGET https://{apiId}.execute-api.{aws}.com/{stage}/v2/
you will see response forListItems
, but if you useapi.example.com
as domain name and if you call it byGET https://api.example.com/v2/
you will be callingGetItem
wherev2
will be mapped parameter for/{id}
.TL;DR:
GET https://{apiId}.execute-api.{aws}.com/{stage}/v2/
- call correctlyListItems
handlerGET https://api.example.com/v2/
- call incorrectlyGetItem
handlerSimilar issue was reported in:
And also implemented in official APIG-Lambda proxy -
awslabs/aws-lambda-go-api-proxy
: https://github.com/awslabs/aws-lambda-go-api-proxy/blob/5aaec6761420bbbd4b1f4cf9e2d6eff552413986/core/request.go#L74-L96Sample usage (example from actual
Readme.md
will be valid too):To sum up:
gateway.ListenAndServe
does not change.BasePathMapping
then he just need to define it via struct field, which is very straightforward in Go.addr string
is marked as ignored via blank identifier - again, non breaking signature Unfortunately, in the example presented inReadme.md
tells to use port-binding mapping, which may lead to misinformation, what exactly this variable do (err.. nothing).Gateway.Serve
method.Note: Registering route twice for different resources is workaround, which works on both type of endpoints.