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

Next 13 (app folder) + nextcrud #53

Open
mfik opened this issue May 23, 2023 · 10 comments
Open

Next 13 (app folder) + nextcrud #53

mfik opened this issue May 23, 2023 · 10 comments
Assignees

Comments

@mfik
Copy link

mfik commented May 23, 2023

Integration with Next 13 with app folder isn't possible, due to the conventions changing. The handler export is changed to GET, POST, PUT, DELETE, etc.

For next, syntax should probably be something like:

export async function GET (req, res) {
  const nextCrudHandler = await NextCrud({
    adapter: new PrismaAdapter({
      prismaClient: prisma,
    })
  })

  return nextCrudHandler(req, res)
}
@mfik
Copy link
Author

mfik commented Sep 5, 2023

Can be fixed with: export { handler as GET, handler as POST } if prisma 5 is supported

@AntonAndreevichMoroz
Copy link

Has anyone managed to get APP route to work? I tried exporting as GET, POST, etc. But it turns out that in the code next-crud tries to send the response itself via res.send(), but in NextJS 14 this no longer works, it expects to receive a JSON response from the Response constructor.
Although NextApiResponse types have a send() method, in fact it is not presented and I get an error that res.send() is undefined.

@sovetski
Copy link
Contributor

Any update? It does not work on v14 too, I have 404 error

@morinted
Copy link

Workaround is to not use the App folder for the API: use pages/api/[...nextcrud].ts

The rest of my code base is still in the app folder and this works where app/api didn't.

@foyarash
Copy link
Contributor

Hello everybody

Sorry for the delay. I have opened a PR to add compatibility with the App Dir #67

There is a bit of breaking changes for on the callbacks but overall it is working for both App and Page router

@ilomon10
Copy link

ilomon10 commented Apr 3, 2024

@foyarash is it ready to use?

@foyarash
Copy link
Contributor

foyarash commented Apr 3, 2024

Published on v4.0.0.

Feel free to report any issue.

@malaney
Copy link
Contributor

malaney commented May 1, 2024

I too am unable to get v4.0.0 of next-crud to fully work using the App Router. The GET requests work, but POST, PUT and DELETE all fail. From what I can tell, the problem seems to be centered around the getRouteType() method and the matchers it uses to parse the path. Every request appears to evaluate to false and the only API route that will work in spite of the matcher returning false is the GET (READ_ALL) route.

@malaney
Copy link
Contributor

malaney commented May 1, 2024

I'm no expert, but here is a small PR that appears to fix the issue.

@foyarash
Copy link
Contributor

foyarash commented May 2, 2024

Thank you for the report & fix @malaney, this has been deployed in v4.0.1

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

7 participants