@@ -101,10 +101,11 @@ function initOutputDir() {
101
101
fs . mkdirSync ( tempDir , { recursive : true } ) ;
102
102
}
103
103
104
- function isMiddlewareEnabled ( ) {
104
+ function getMiddlewareName ( ) {
105
+ // note: middleware can be at the root or inside "src"
105
106
const filePath = path . join ( appPath , ".next" , "server" , "middleware-manifest.json" ) ;
106
107
const json = fs . readFileSync ( filePath , "utf-8" ) ;
107
- return JSON . parse ( json ) . sortedMiddleware . length > 0 ;
108
+ return JSON . parse ( json ) . middleware ?. [ "/" ] ?. name ;
108
109
}
109
110
110
111
function createServerBundle ( monorepoRoot : string ) {
@@ -219,7 +220,8 @@ function createImageOptimizationBundle() {
219
220
}
220
221
221
222
function createMiddlewareBundle ( buildOutput : any ) {
222
- if ( isMiddlewareEnabled ( ) ) {
223
+ const middlewareName = getMiddlewareName ( ) ;
224
+ if ( middlewareName ) {
223
225
console . info ( `Bundling middleware edge function...` ) ;
224
226
}
225
227
else {
@@ -232,7 +234,7 @@ function createMiddlewareBundle(buildOutput: any) {
232
234
fs . mkdirSync ( outputPath , { recursive : true } ) ;
233
235
234
236
// Save middleware code to file
235
- const src : string = buildOutput . output . middleware . files [ "index.js" ] . data ;
237
+ const src : string = buildOutput . output [ middlewareName ] . files [ "index.js" ] . data ;
236
238
fs . writeFileSync ( path . join ( tempDir , "middleware.js" ) , src ) ;
237
239
fs . copyFileSync (
238
240
path . join ( __dirname , "adapters" , "middleware-adapter.js" ) ,
0 commit comments