Skip to content

Commit

Permalink
fix(nextjs): additional experimental HTTPS flags
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed May 17, 2024
1 parent d289134 commit e66a98e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
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

0 comments on commit e66a98e

Please sign in to comment.