Skip to content
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

API routes in NextJS don't return any data #501

Closed
ekasprzyk opened this issue Aug 30, 2024 · 4 comments
Closed

API routes in NextJS don't return any data #501

ekasprzyk opened this issue Aug 30, 2024 · 4 comments

Comments

@ekasprzyk
Copy link

Over on SST Ion we posted this issue:

sst/sst#4282

We've just tried moving from Serverless Components to SST for the deployment of our disposable branch environments and we're trying to replace that with SST before we think about moving the main site over.

We've had a lot of luck getting our site working on SST, but there's one thing that is behaving a bit weird that we just can't figure out. Not sure if this is a bug or just a documentation/concept error or whatever. So I'll just ask our question here as I haven't been able to find any information on it at all.

We have a NextJS 12.x site which we deploy via serverless components. That deploy uses Cloudfront and has an s3 bucket with default and API lambdas attached to it.

We've tried redeploying the same thing with SST and it's worked, mostly. We can see the site, some content even loads. We're nearly there. But, for reasons we don't understand, the `/api' routes are not returning data. We can see the routes being called in logs, we can see the current status being returned (e.g. one of our routes returns 500 due to a misconfiguration we haven't fixed, and that's correct, others return correct 200s). But no JSON. No data is being returned.

When trying to understand it a bit better, we notice that there is no longer an API lambda in the deployment, but that everything goes through the default lambda and we think that's normal based on the diagram of the system architecture.

Any advice on what we're doing wrong? And if so, any documentation that could be written to help others (assuming we're not being idiots)?

Also, we're noticing there aren't any edge functions that we can obviously tell in Cloudfront, and don't know if we have some issues with that as well.

One of the responders there mentioned it could be an issue with us using Next 12 and suggested we ask here. Any ideas, and does it seem most likely (as they suggest) that our issue is due to using Next 12 with the latest version of OpenNext?

Thanks!

@khuezy
Copy link
Contributor

khuezy commented Aug 30, 2024

You should upgrade to the latest 14, there are some breaking changes from 12 => 13, but it should be pretty minor.

@jfacchini
Copy link

jfacchini commented Oct 22, 2024

Hi @khuezy, we have now upgraded the application over to Next.js 14.

The /api/* routes are now returning 304 Not Modified responses. Looking at the Default lambda logs, we cannot see any logs from these routes.

We then tried to call one /api endpoint with postman. This managed to reach the Default lambda, as we can see some logs but the response body is still empty.

@conico974
Copy link
Contributor

@jfacchini What headers do you get ? It looks like this is cached in the cdn

@ekasprzyk
Copy link
Author

@conico974 Thanks for your help. We managed to fix the issue and we found out what was causing it.

Seems to have been a repeat of: #350

For others who come here, we both removed Sentry (we were going to do this anyway) and upgraded to OpenNext v3. These both seemed to fix the problem, although due to caching issues, we'll never know which (one, the other or both) fixed it.

Closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants