Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): empty port should not overwrite env port #20751

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/src/executors/server/custom-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default async function* serveExecutor(
: 'production';

// Setting port that the custom server should use.
(process.env as any).PORT = options.port;
process.env.PORT = options.port ? `${options.port}` : process.env.PORT;
options.port = parseInt(process.env.PORT);

const projectRoot = context.projectGraph.nodes[context.projectName].data.root;

Expand Down
11 changes: 6 additions & 5 deletions packages/next/src/executors/server/server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function* serveExecutor(
);
const projectRoot = context.workspace.projects[context.projectName].root;

const { port, keepAliveTimeout, hostname } = options;
const { keepAliveTimeout, hostname } = options;

// This is required for the default custom server to work. See the @nx/next:app generator.
process.env.NX_NEXT_DIR = projectRoot;
Expand All @@ -42,9 +42,10 @@ export default async function* serveExecutor(
: 'production';

// Setting port that the custom server should use.
process.env.PORT = `${options.port}`;
process.env.PORT = options.port ? `${options.port}` : process.env.PORT;
options.port = parseInt(process.env.PORT);

const args = createCliOptions({ port, hostname });
const args = createCliOptions({ port: options.port, hostname });

if (keepAliveTimeout && !options.dev) {
args.push(`--keepAliveTimeout=${keepAliveTimeout}`);
Expand Down Expand Up @@ -81,11 +82,11 @@ export default async function* serveExecutor(
process.on('SIGTERM', () => killServer());
process.on('SIGHUP', () => killServer());

await waitForPortOpen(port, { host: options.hostname });
await waitForPortOpen(options.port, { host: options.hostname });

next({
success: true,
baseUrl: `http://${options.hostname ?? 'localhost'}:${port}`,
baseUrl: `http://${options.hostname ?? 'localhost'}:${options.port}`,
});
}
);
Expand Down