-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Req.url incorrectly evaluated for paths with nested proxy - ApiGateway #400
Comments
This appears related: |
is there a workaround for this? my use case is wanting to create a callback url to a path, and with the same url structure as @saltonmassally has defined above. |
I've found a workaround for this, in my specific case I had to do this:
|
Thank you for this. It worked perfectly for my scenario as well. In my case, the fix was export const handler: APIGatewayProxyHandler = async (event, context, callback) => {
// Enable support for a "version" pathParameter that was defined in the AWS CDK project stack.
// In the stack, the greedy proxy (.addProxy()) is attached to this resource.
const nextEvent: APIGatewayProxyEvent = {
...event,
resource: event.resource.replace(/^\/{version}/, ''),
requestContext: {
...(event.requestContext ?? {}),
resourcePath: event.requestContext.resourcePath.replace(/^\/{version}/, '')
},
pathParameters: {
...(event.pathParameters ?? {}),
// Get the actual value of the "version" pathParameter and prefix it to the value of "proxy"
proxy: `${event.pathParameters?.['version']}/${event.pathParameters?.['proxy']}`
}
};
server = await boostrap();
// Pass the modified event to the serverless express handler
return server(nextEvent, context, callback);
};
|
I got the same error. import serverlessExpress from 'aws-serverless-express';
async function bootstrap(): Promise<Server> {
const app = await NestFactory.create(AppModule, {
logger: ['error', 'warn'],
});
await app.init();
const expressApp = app.getHttpAdapter().getInstance();
return serverlessExpress.createServer(expressApp);
}
export const handler: Handler = async (
event: APIGatewayProxyEvent,
context: Context,
) => {
server = server ?? (await bootstrap());
return serverlessExpress.proxy(server, event, context, 'PROMISE').promise;
}; |
GIven the following resource
/testing/{proxy+}
a call to/testing/creategroup
is evaluated to/creategroup
rather than/testing/creatgroup
.Looking at getPathWithQueryStringParams, it appears that if proxy pathParameter is present, it is simply used, discarding the other parts. Would substituting the value for proxy for the token {proxxy+} into
event.resource
(/testing/{proxy+}) be a potential approach to fixing this?The text was updated successfully, but these errors were encountered: