Skip to content

Commit 0e0e259

Browse files
committed
added explanation about "catch-all" API route that works both on app router and pages router
1 parent 590f262 commit 0e0e259

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/NextJs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Now the admin renders at `http://localhost:3000/admin`, and you can use the Next
141141

142142
## Adding an API
143143

144-
[Next.js allows to serve an API](https://nextjs.org/docs/api-routes/introduction) from the same server. You *could* use this to build a CRUD API by hand. However, we consider that building a CRUD API on top of a relational database is a solved problem and that developers shouldn't spend time reimplementing it.
144+
Never mind the router system you choose, [Next.js allows to serve an API](https://nextjs.org/docs/api-routes/introduction) from the same server. You *could* use this to build a CRUD API by hand. However, we consider that building a CRUD API on top of a relational database is a solved problem and that developers shouldn't spend time reimplementing it.
145145

146146
For instance, if you store your data in a [PostgreSQL](https://www.postgresql.org/) database, you can use [PostgREST](https://postgrest.org/en/stable/) to expose the data as a REST API with zero configuration. Even better, you can use a Software-as-a-Service like [Supabase](https://supabase.com/) to do that for you.
147147

@@ -170,7 +170,7 @@ SUPABASE_SERVICE_ROLE="MY_SERVICE_ROLE_KEY"
170170
Create [a "catch-all" API route](https://nextjs.org/docs/api-routes/dynamic-api-routes#optional-catch-all-api-routes) in the Next.js app by adding a `pages/api/admin/[[...slug]].ts` file. This API route redirects all calls from the react-admin app to the Supabase CRUD API:
171171

172172
```tsx
173-
// in pages/api/admin/[[...slug]].ts
173+
// in src/pages/api/admin/[[...slug]].ts
174174
import { NextApiRequest, NextApiResponse } from "next";
175175

176176
export default async function handler(req: NextApiRequest, res: NextApiResponse) {

0 commit comments

Comments
 (0)