Skip to content

Commit 243baac

Browse files
committed
hack for deployed lambda
1 parent be8ad61 commit 243baac

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

packages/open-next/src/build/copyTracedFiles.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,38 @@ File ${fullFilePath} does not exist
142142
};
143143

144144
if (existsSync(path.join(dotNextDir, "server/middleware.js.nft.json"))) {
145-
//TODO: For now we copy the middleware.js file not from the standalone dir, this will probably be removed in the future
146-
filesToCopy.set(
145+
//FIXME: This is a hack to make sure we include the middleware files
146+
// Next should copy everything necessary into the standalone dir
147+
// Once they've done that we can replace all these shenanigans with a single computeCopyFilesForPage
148+
copyFileSync(
147149
path.join(dotNextDir, "server/middleware.js"),
148-
path.join(outputNextDir, "server/middleware.js"),
150+
path.join(standaloneNextDir, "server/middleware.js"),
151+
);
152+
copyFileSync(
153+
path.join(dotNextDir, "server/middleware.js.nft.json"),
154+
path.join(standaloneNextDir, "server/middleware.js.nft.json"),
155+
);
156+
const requiredMiddlewareFiles = JSON.parse(
157+
readFileSync(
158+
path.join(dotNextDir, "server/middleware.js.nft.json"),
159+
"utf8",
160+
),
149161
);
150-
safeComputeCopyFilesForPage("middleware");
162+
extractFiles(
163+
requiredMiddlewareFiles.files.map((f: string) =>
164+
f.startsWith("../") ? `../${f}` : `server/${f}`,
165+
),
166+
).forEach((f) => {
167+
filesToCopy.set(
168+
f,
169+
f
170+
.replace(standaloneDir, outputDir)
171+
.replace(
172+
path.join(buildOutputPath, "node_modules"),
173+
path.join(outputDir, "node_modules"),
174+
),
175+
);
176+
});
151177
}
152178

153179
const hasPageDir = routes.some((route) => route.startsWith("pages/"));

0 commit comments

Comments
 (0)