codeledge / ra-tools

React Admin Tools, namely the Prisma Data Adapter
67 stars 19 forks source link

Documentation Update Suggestion (to show how to work with NextJS App Router) #66

Closed benjamindell closed 1 year ago

benjamindell commented 1 year ago

Sorry for posting as an issue, i wasnt sure where else to post this.

I struggled to get this data provider working with the NextJS App Router approach. I now have it working and so i thought i'd share the code in case you want to add it to your readme.

In short, i had to create a folder and file at app/api/[resource]/route.ts

And then in route.ts, i added:

`// /api/[resource]/route.ts <= catch all resource requests import { defaultHandler } from "ra-data-simple-prisma"; import { NextResponse } from "next/server"; import prisma from "@/utils/db";

// POST request export async function POST(req: Request) { let reqCloned = req.clone(); const body = await req.json(); let res = await defaultHandler({ body }, reqCloned, prisma); return NextResponse.json(res); }`

ogroppo commented 1 year ago

Hey, thank you for raising this, yes of course I'll add an example for app router!