nextjs-lambda icon indicating copy to clipboard operation
nextjs-lambda copied to clipboard

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

Open js-sapphire opened this issue 1 year ago • 5 comments

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:

  • In a standalone app, I can see we have code.zip and dependencies.zip, the two of which need to be deployed for Lambda. I dont see a file structure for <buildId>/index.json. Is there a need for these files to exist in the directory ?
  • Is this a problem with Next 13 ?

js-sapphire avatar Dec 21 '23 06:12 js-sapphire

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).

sladg avatar Dec 21 '23 14:12 sladg

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 avatar Dec 21 '23 15:12 js-sapphire

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 )

js-sapphire avatar Dec 21 '23 16:12 js-sapphire

@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.

sladg avatar Dec 21 '23 18:12 sladg

Thanks @sladg Will share ASAP.

js-sapphire avatar Dec 21 '23 18:12 js-sapphire

Closing, inactive :)

sladg avatar Oct 06 '24 09:10 sladg