@@ -4,6 +4,7 @@ import type { Bridge as NodeBridge } from '@vercel/node-bridge/bridge'
4
4
import { outdent as javascript } from 'outdent'
5
5
6
6
import type { NextConfig } from '../helpers/config'
7
+ import { splitApiRoutes as isSplitApiRoutesEnabled } from '../helpers/flags'
7
8
8
9
import type { NextServerType } from './handlerUtils'
9
10
import type { NetlifyNextServerType } from './server'
@@ -30,10 +31,11 @@ type MakeApiHandlerParams = {
30
31
app : string
31
32
pageRoot : string
32
33
NextServer : NextServerType
34
+ splitApiRoutes : boolean
33
35
}
34
36
35
37
// We return a function and then call `toString()` on it to serialise it as the launcher function
36
- const makeApiHandler = ( { conf, app, pageRoot, NextServer } : MakeApiHandlerParams ) => {
38
+ const makeApiHandler = ( { conf, app, pageRoot, NextServer, splitApiRoutes } : MakeApiHandlerParams ) => {
37
39
// Change working directory into the site root, unless using Nx, which moves the
38
40
// dist directory and handles this itself
39
41
const dir = path . resolve ( __dirname , app )
@@ -88,6 +90,7 @@ const makeApiHandler = ({ conf, app, pageRoot, NextServer }: MakeApiHandlerParam
88
90
} ,
89
91
{
90
92
revalidateToken : customContext ?. odb_refresh_hooks ,
93
+ splitApiRoutes,
91
94
} ,
92
95
)
93
96
const requestHandler = nextServer . getRequestHandler ( )
@@ -134,11 +137,13 @@ export const getApiHandler = ({
134
137
publishDir = '../../../.next' ,
135
138
appDir = '../../..' ,
136
139
nextServerModuleRelativeLocation,
140
+ featureFlags,
137
141
} : {
138
142
schedule ?: string
139
143
publishDir ?: string
140
144
appDir ?: string
141
145
nextServerModuleRelativeLocation : string | undefined
146
+ featureFlags : Record < string , unknown >
142
147
} ) : string =>
143
148
// This is a string, but if you have the right editor plugin it should format as js (e.g. bierner.comment-tagged-templates in VS Code)
144
149
javascript /* javascript */ `
@@ -161,6 +166,8 @@ export const getApiHandler = ({
161
166
let staticManifest
162
167
const path = require ( "path" ) ;
163
168
const pageRoot = path . resolve ( path . join ( __dirname , "${ publishDir } " , "server" ) ) ;
164
- const handler = ( ${ makeApiHandler . toString ( ) } ) ( { conf : config , app : "${ appDir } " , pageRoot, NextServer} )
169
+ const handler = ( ${ makeApiHandler . toString ( ) } ) ( { conf : config , app : "${ appDir } " , pageRoot, NextServer, splitApiRoutes : ${ isSplitApiRoutesEnabled (
170
+ featureFlags ,
171
+ ) } } )
165
172
exports . handler = ${ schedule ? `schedule(${ JSON . stringify ( schedule ) } , handler);` : 'handler' }
166
173
`
0 commit comments