Reduce image size by pruning stuff and things

Ref https://github.com/orgs/fosrl/discussions/2069
This commit is contained in:
Owen
2026-10-12 15:41:50 -04:00
parent 3d590493d6
commit 9afcd68d68
3 changed files with 112 additions and 18 deletions
+22 -1
View File
@@ -1,5 +1,7 @@
import next from "next";
import express from "express";
import fs from "fs";
import path from "path";
import { parse } from "url";
import logger from "@server/logger";
import config from "@server/lib/config";
@@ -8,9 +10,28 @@ import { stripDuplicateSesions } from "./middlewares/stripDuplicateSessions";
const nextPort = config.getRawConfig().server.next_port;
export async function createNextServer() {
const dev = process.env.ENVIRONMENT !== "prod";
// The image only ships the files Next traced for its standalone output,
// which leaves out what is needed to load next.config at runtime. Hand
// Next the config resolved at build time instead, the same way the
// generated .next/standalone/server.js does.
const requiredServerFilesPath = path.join(
process.cwd(),
".next",
"required-server-files.json"
);
if (!dev && fs.existsSync(requiredServerFilesPath)) {
const { config: nextConfig } = JSON.parse(
fs.readFileSync(requiredServerFilesPath, "utf8")
);
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG =
JSON.stringify(nextConfig);
}
// const app = next({ dev });
const app = next({
dev: process.env.ENVIRONMENT !== "prod",
dev,
turbopack: false
});
const handle = app.getRequestHandler();