Open jimmythomson opened 3 years ago
I've encountered this issue. Kinda similar to the one reported here. Were you able to find a solution?
Hi @ninjazhai - I just had a look back at some code that I was writing when I ran in to this problem, and it looks like I just had to create a route where the path was a blank string, i.e. app.get('', myHandler)
rather than a single forward slash. Hope that helps you.
A workaround with older versions was:
if(event.resource === "/"){
event.path = '/your-base-path';
}
Solution
exports.handler = (event, context) => {
if (event.pathParameters ==null ) {
event.path = '/';
}
else{
event.path = '/'+event.pathParameters.proxy;
}
awsServerlessExpress.proxy(server, event, context);
}
If I try and
GET /my-base-path
on an app wherebasePath
is set to/my-base-path
, the underlyingevent.path
appears to be set to a blank string, which then results in express responding with a 404 with the messageCannot GET null
. Could someone confirm that this is indeed a bug rather than me not implementing/using something correctly? Happy to create a PR to resolve this if indeed it is an issue. Thanks.