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

Pages Router catchAll route with fallback:false cause 404 on api route #677

Open
gabriel-wow opened this issue Dec 16, 2024 · 11 comments · May be fixed by #679 or sommeeeer/opennextjs-aws#1
Open

Pages Router catchAll route with fallback:false cause 404 on api route #677

gabriel-wow opened this issue Dec 16, 2024 · 11 comments · May be fixed by #679 or sommeeeer/opennextjs-aws#1

Comments

@gabriel-wow
Copy link

gabriel-wow commented Dec 16, 2024

My company has a large project built with Next.js 12. As Next.js 12 is now outdated, we updated our project to Next.js 14 while keeping the Pages Router structure. Previously, we were using cdk-nextjs-standalone to deploy the application to AWS, and everything was working fine.
However, after upgrading to Next.js 14 and deploying, our API routes topped functioning. To resolve this, we decided to migrate to the SST framework (v3). Despite completing the migration and configuration, our API routes are still not working and continue sending us to 404 page.

Versions:
Next.js: v14.2.20
SST: v3.3.65
OpenNext.js: 3.2.2

Steps Taken:

Updated Next.js from v12 to v14 (keeping the Pages Router structure).
Migrated deployment from cdk-nextjs-standalone to SST (v3).
Configured the SST project following the documentation.
Even after successfully deploying the project with SST v3, our API routes are unresponsive.

Another point to add is that we performed a fresh install deployment of Next.js v15 using the Pages Router, and the APIs are not working either.

@conico974
Copy link
Contributor

You need to provide more info here or even better a reproduction.
What's in your next-config ?

@conico974 conico974 added the need reproduction This issue need a reproduction in order to be fixed label Dec 16, 2024
@gabriel-wow
Copy link
Author

My project is a monorepo with Lerna

image

@sommeeeer
Copy link
Contributor

sommeeeer commented Dec 16, 2024

Are you using tRPC or anything special with those API routes? You should probably look in CloudWatch logs aswell and see if you can see anything on the default server function.

Whats in your package.json?

@fthomasvp-wow
Copy link

fthomasvp-wow commented Dec 16, 2024

Hi,

The issue also happens on Next 15 (Pages Router).

Steps to Reproduce

  1. Create a project using the create-next-app
  2. Add a catch-all dynamic route at the top level of the pages directory
  3. Make sure there is at least one API route in the pages/api directory

image

Environment

Node.js 20.14.0
Next.js 15.1.0
SST 3.4.2
OpenNext 3.2.2

Notes

  • The .next/standalone/server.js generated by running the open-next build command works as expected.
  • Here's the .open-next/server-functions/default/.next/routes-manifest.json generated by running the open-next build command:
    image
    With catch-all dynamic route

image
Without catch-all dynamic route

@conico974
Copy link
Contributor

Are you using fallback:false ?

@fthomasvp-wow
Copy link

fthomasvp-wow commented Dec 16, 2024

Are you using fallback:false ?

Yes!

There is also a dynamic route using fallback: blocking (in the monorepo project mentioned by @gabriel-wow ) that works fine (when no catch-all dynamic route is present in the pages directory).

@conico974
Copy link
Contributor

We need to change that, right now catchAll fallback:false route takes precedence over everything else.

As a workaround set it to fallback:true and return notFound for paths you don't want https://nextjs.org/docs/pages/api-reference/functions/get-static-props#notfound

@fthomasvp-wow
Copy link

Got it! We'll make the changes, and update this thread with the results.

Thanks for your quick reply @sommeeeer @conico974

@fthomasvp-wow
Copy link

Hi,

Your tip did the trick... Both Pages and APIs are working as expected.

Out of curiosity... Are you guys planning to release a fix soon?

Big thanks for your help!!! You guys rock 😄

@conico974
Copy link
Contributor

This will require a bunch of change to work properly. And since there is a very simple workaround it's not high priority.
I'll keep this open until we fix it, but i'll rename the issue

@conico974 conico974 changed the title Pages Router APIs not working after migration to SST v3 Pages Router catchAll route with fallback:false cause 404 on api route Dec 16, 2024
@gabriel-wow
Copy link
Author

Hi @sommeeeer @conico974,
Thank you so much for help and the quick response, it seems to have worked!!

@github-actions github-actions bot linked a pull request Dec 17, 2024 that will close this issue
@conico974 conico974 removed the need reproduction This issue need a reproduction in order to be fixed label Dec 17, 2024
@github-actions github-actions bot linked a pull request Dec 17, 2024 that will close this 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

Successfully merging a pull request may close this issue.

4 participants