-
Notifications
You must be signed in to change notification settings - Fork 108
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
Unable to Deploy Serverless with API Gateway #414
Comments
First of all, what version of next and OpenNext are you using ? And how are you setting up the IAC for this (cdk, terraform... ) ? If you absolutely need to keep those basePath, you could use a custom wrapper to remove the basePath before passing it to the server function. https://open-next.js.org/inner_workings/components/overview#wrapper. |
I'm on Next.js v14.1.1 and OpenNext v2.3.9. Using Terraform for IaC. We have to go through a proxy between CloudFront and API GW. The image-optimization-function is not a problem. The issue is with the server-function at root path.
|
I'm not sure i understand you setup here. You have Cloudfront that goes to a lambda proxy and then to Api GW that itself forward stuff to the server function ? And yeah the wrapper functionnality is in V3, in V2 you could just create an export const handler = async (event, context) => {
// Modify the rawPath and url in event here
const { handler: rawHandler} = await import("./index.mjs");
return rawHandler(event, context);
}; |
I managed to resolve the issue by proxying the root path of the API Gateway to the server lambda thanks to this advice.
The proxy is from an API portal to proxy the traffic from external CloudFront to internal API Gateway behind a VPC. |
We are migrating from @sladg/nextjs-lambda which uses API Gateway to proxy traffic from CloudFront to the Lambda functions at /_server and /_image paths. Due to security restrictions, we have to continue using API Gateway for proxy instead of Lambda function URL as seen in the architecture diagram.
After several rounds of testing and debugging, I can't figure out why my website always redirects from "/" to "/_server". As a result, I could only access the 404 page of my site. Debugging with CloudWatch shows that my Lambda proxy is receiving the path and x-forwarded-path as "/_server/_server."
I tried to set the basePath = "/server" in next.config.js but this only fixes my /api endpoints to not return 404. The "/" path continues to redirect to "/_server" and results in 404. I also had to fix the paths for /_next* to /_server/_next* in CloudFront with this config change.
I'm running out of ideas so hopefully I can get some answers on the feasibility of using API GW with paths /_image proxied to image-optimization-function and /_server proxied to server-function.
The text was updated successfully, but these errors were encountered: