Skip to content

Commit 229c032

Browse files
authored
Add support for Next.js "src" directory (#26)
1 parent 9c56400 commit 229c032

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/build.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ function initOutputDir() {
101101
fs.mkdirSync(tempDir, { recursive: true });
102102
}
103103

104-
function isMiddlewareEnabled() {
104+
function getMiddlewareName() {
105+
// note: middleware can be at the root or inside "src"
105106
const filePath = path.join(appPath, ".next", "server", "middleware-manifest.json");
106107
const json = fs.readFileSync(filePath, "utf-8");
107-
return JSON.parse(json).sortedMiddleware.length > 0;
108+
return JSON.parse(json).middleware?.["/"]?.name;
108109
}
109110

110111
function createServerBundle(monorepoRoot: string) {
@@ -219,7 +220,8 @@ function createImageOptimizationBundle() {
219220
}
220221

221222
function createMiddlewareBundle(buildOutput: any) {
222-
if (isMiddlewareEnabled()) {
223+
const middlewareName = getMiddlewareName();
224+
if (middlewareName) {
223225
console.info(`Bundling middleware edge function...`);
224226
}
225227
else {
@@ -232,7 +234,7 @@ function createMiddlewareBundle(buildOutput: any) {
232234
fs.mkdirSync(outputPath, { recursive: true });
233235

234236
// 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;
236238
fs.writeFileSync(path.join(tempDir, "middleware.js"), src);
237239
fs.copyFileSync(
238240
path.join(__dirname, "adapters", "middleware-adapter.js"),

0 commit comments

Comments
 (0)