Skip to content

Commit

Permalink
fix(nextjs): custom server unable to run production builds (#21222)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham committed Jan 19, 2024
1 parent 6684c1f commit 605d65a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/executors/server/custom-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function* runCustomServer(
options: NextServeBuilderOptions,
context: ExecutorContext
) {
process.env.NX_NEXT_DIR = root;
process.env.NX_NEXT_DIR ??= root;
process.env.NX_NEXT_PUBLIC_DIR = join(root, 'public');

const baseUrl = `http://${options.hostname || 'localhost'}:${options.port}`;
Expand Down
16 changes: 7 additions & 9 deletions packages/next/src/executors/server/server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ export default async function* serveExecutor(
options: NextServeBuilderOptions,
context: ExecutorContext
) {
if (options.customServerTarget) {
return yield* customServer(options, context);
}

const buildOptions = readTargetOptions<NextBuildBuilderOptions>(
parseTargetString(options.buildTarget, context),
context
);
const projectRoot = context.workspace.projects[context.projectName].root;
// This is required for the default custom server to work. See the @nx/next:app generator.
const nextDir = resolve(context.root, buildOptions.outputPath);
process.env.NX_NEXT_DIR ??= options.dev ? projectRoot : nextDir;

const { keepAliveTimeout, hostname } = options;
if (options.customServerTarget) {
return yield* customServer(options, context);
}

// This is required for the default custom server to work. See the @nx/next:app generator.
process.env.NX_NEXT_DIR = projectRoot;
const { keepAliveTimeout, hostname } = options;

// Cast to any to overwrite NODE_ENV
(process.env as any).NODE_ENV = process.env.NODE_ENV
Expand All @@ -51,8 +51,6 @@ export default async function* serveExecutor(
args.push(`--keepAliveTimeout=${keepAliveTimeout}`);
}

const nextDir = resolve(context.root, buildOptions.outputPath);

const mode = options.dev ? 'dev' : 'start';
const turbo = options.turbo && options.dev ? '--turbo' : '';
const experimentalHttps =
Expand Down

0 comments on commit 605d65a

Please sign in to comment.