@@ -6,11 +6,12 @@ import { AppRouteRequestHandlerOptions } from '.';
6
6
import { RPCApiHandler } from '../api' ;
7
7
import { loadAssets } from '../shared' ;
8
8
9
- type Context = { params : { path : string [ ] } } ;
9
+ type Context = { params : Promise < { path : string [ ] } > | { path : string [ ] } } ;
10
10
11
11
/**
12
12
* Creates a Next.js 13 "app dir" API route request handler which encapsulates Prisma CRUD operations.
13
13
*
14
+ * @remarks Since Next.js 15, `context.params` is asynchronous and must be awaited.
14
15
* @param options Options for initialization
15
16
* @returns An API route request handler
16
17
*/
@@ -27,18 +28,25 @@ export default function factory(
27
28
return NextResponse . json ( { message : 'unable to get prisma from request context' } , { status : 500 } ) ;
28
29
}
29
30
31
+ let params : Context [ 'params' ] ;
30
32
const url = new URL ( req . url ) ;
31
33
const query = Object . fromEntries ( url . searchParams ) ;
32
34
33
- if ( ! context . params . path ) {
35
+ try {
36
+ params = await context . params ;
37
+ } catch {
38
+ return NextResponse . json ( { message : 'Failed to resolve request parameters' } , { status : 500 } ) ;
39
+ }
40
+
41
+ if ( ! params . path ) {
34
42
return NextResponse . json (
35
43
{ message : 'missing path parameter' } ,
36
44
{
37
45
status : 400 ,
38
46
}
39
47
) ;
40
48
}
41
- const path = context . params . path . join ( '/' ) ;
49
+ const path = params . path . join ( '/' ) ;
42
50
43
51
let requestBody : unknown ;
44
52
if ( req . body ) {
0 commit comments