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): additional experimental HTTPS options #23334

Merged
merged 1 commit into from
May 17, 2024
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
12 changes: 12 additions & 0 deletions docs/generated/packages/next/executors/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@
"type": "boolean",
"description": "Enable HTTPS support for the Next.js development server."
},
"experimentalHttpsKey": {
"type": "string",
"description": "Path to a HTTPS key file."
},
"experimentalHttpsCert": {
"type": "string",
"description": "Path to a HTTPS certificate file."
},
"experimentalHttpsCa": {
"type": "string",
"description": "Path to a HTTPS certificate authority file."
},
"customServerHttps:": {
"type": "boolean",
"description": "Enable HTTPS support for the custom server."
Expand Down
12 changes: 12 additions & 0 deletions packages/next/src/executors/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@
"type": "boolean",
"description": "Enable HTTPS support for the Next.js development server."
},
"experimentalHttpsKey": {
"type": "string",
"description": "Path to a HTTPS key file."
},
"experimentalHttpsCert": {
"type": "string",
"description": "Path to a HTTPS certificate file."
},
"experimentalHttpsCa": {
"type": "string",
"description": "Path to a HTTPS certificate authority file."
},
"customServerHttps:": {
"type": "boolean",
"description": "Enable HTTPS support for the custom server."
Expand Down
29 changes: 22 additions & 7 deletions packages/next/src/executors/server/server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
parseTargetString,
readTargetOptions,
} from '@nx/devkit';
import { join, resolve } from 'path';
import { resolve } from 'path';

import {
NextBuildBuilderOptions,
Expand Down Expand Up @@ -54,16 +54,18 @@ export default async function* serveExecutor(

const mode = options.dev ? 'dev' : 'start';
const turbo = options.turbo && options.dev ? '--turbo' : '';
const experimentalHttps =
options.experimentalHttps && options.dev ? '--experimental-https' : '';
const nextBin = require.resolve('next/dist/bin/next');

yield* createAsyncIterable<{ success: boolean; baseUrl: string }>(
async ({ done, next, error }) => {
const server = fork(nextBin, [mode, ...args, turbo, experimentalHttps], {
cwd: options.dev ? projectRoot : nextDir,
stdio: 'inherit',
});
const server = fork(
nextBin,
[mode, ...args, turbo, ...getExperimentalHttpsFlags(options)],
{
cwd: options.dev ? projectRoot : nextDir,
stdio: 'inherit',
}
);

server.once('exit', (code) => {
if (code === 0) {
Expand Down Expand Up @@ -92,3 +94,16 @@ export default async function* serveExecutor(
}
);
}

function getExperimentalHttpsFlags(options: NextServeBuilderOptions): string[] {
if (!options.dev) return [];
const flags: string[] = [];
if (options.experimentalHttps) flags.push('--experimental-https');
if (options.experimentalHttpsKey)
flags.push(`--experimental-https-key=${options.experimentalHttpsKey}`);
if (options.experimentalHttpsCert)
flags.push(`--experimental-https-cert=${options.experimentalHttpsCert}`);
if (options.experimentalHttpsCa)
flags.push(`--experimental-https-ca=${options.experimentalHttpsCa}`);
return flags;
}
3 changes: 3 additions & 0 deletions packages/next/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export interface NextServeBuilderOptions {
keepAliveTimeout?: number;
turbo?: boolean;
experimentalHttps?: boolean;
experimentalHttpsKey?: string;
experimentalHttpsCert?: string;
experimentalHttpsCa?: string;
customServerHttps?: boolean;
}

Expand Down