sladg / nextjs-lambda

Lambda deployments for Nextjs12 & Nextjs13 (standalone). Easy CLI commands to get your standalone Next output to run in AWS Lambda (not @Edge)! Uses CDK in behind and produces code zips importable to Terraform, Serverless, Azure, etc.
MIT License
173 stars 19 forks source link

API calls to _next/data fails with a 404 in standalone deployment with AWS Lambda #98

Open js-sapphire opened 9 months ago

js-sapphire commented 9 months ago

I am building an SSR application with Next 13 with standalone output. No basepath. And I am using Page Router. We have certain places where we are doing client side navigation which is triggering an API call ( _next/data/buildId/index.json ) but it fails with a 404. Now, these requests are being sent to the Lambda but they fail and that results in a page refresh.

My questions were:

sladg commented 9 months ago

Hey! _next/data are basically API route I believe. It's handled by Next's server.

'_next/data/*': {
     ...defaultOptions,
     origin: serverOrigin,
},

What seems weird is that doubled // in your path _next/data//index.json. I would imagine that causing and issue probably. Question is, why is it doubled 🤔 Could you investigate the origin of this request (I would expect getServerSideProps making it).

js-sapphire commented 9 months ago

That was a typo. The request is expected. Origin of request is the client. When there is a client side navigation within the app on the same route ( but on a different query string parameter ), client makes a request to getServerSideProps in the form of /_next/data/buildId/index.json. However, it seems Lambda is not able to figure out what to make of it.

Not a typo. Happened because I used carets

js-sapphire commented 9 months ago

I can spin up an example and share repo if that helps. I couldn't find much info on Next SSR Standalone + AWS Lambda but for your package's github. Let me know if that'd help in your investigation ( if you have time for this ofcourse )

sladg commented 9 months ago

@js-sapphire I tried replicating without much luck :/ could you try to share repo steps? I will try to support you, however, please consider EOL (#97) for this package.

js-sapphire commented 9 months ago

Thanks @sladg Will share ASAP.