req.path is different between default API Gateway domain and custom domain
See original GitHub issueAccording to this guide:
setting base path mappings on a custom domain should produce the same result as the default API Gateway domain. However, this is the result I’m seeing with my router (using {proxy+}):
https://udxjef.execute-api.us-east-1.amazonaws.com/pro/foo => req.path is “/foo” https://apis.example.com/petstore/foo => req.path is “/petstore/foo”
Since these paths are different, a route will not be able to match both URLs at the same time.
In our case, we have been able to work around this by setting an environment variable in our Lambda function and then telling our routes that they are mounted to a base path:
app.get(process.env.API_PATH + '/foo', myRouteHandler)
We can then include the same base path on the default URL to get the equivalent route as would be seen by the custom domain:
https://udxjef.execute-api.us-east-1.amazonaws.com/pro/petstore/foo => req.path is “/petstore/foo” https://apis.example.com/petstore/foo => req.path is “/petstore/foo”
This works, but it seems like an unnecessary step and is inconsistent with the expectations outlined in the guide noted above.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:24
- Comments:24
Top GitHub Comments
Try to use this code as your handler:
Any update for this? Really want to use aws-serverless-express without resorting to custom hacks. Thanks. 😄