Skip to content

Commit

Permalink
fix(#10769) Add workaround for microsoft/vscode-remote-release#7029 b…
Browse files Browse the repository at this point in the history
…y using IPv4 loopback when in Remote Container environment
  • Loading branch information
GingerGeek committed Dec 14, 2024
1 parent ff5be65 commit 36cc19c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/docusaurus/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {applyTrailingSlash} from '@docusaurus/utils-common';
import {loadSiteConfig} from '../server/config';
import {build} from './build/build';
import {getHostPort, type HostPortOptions} from '../server/getHostPort';
import {forceV4OnRemoteContainers} from '../server/remoteContainersHook';
import type {LoadContextParams} from '../server/site';

function redirect(res: http.ServerResponse, location: string) {
Expand All @@ -41,6 +42,8 @@ export async function serve(
const buildDir = cliOptions.dir ?? DEFAULT_BUILD_DIR_NAME;
const outDir = path.resolve(siteDir, buildDir);

forceV4OnRemoteContainers(cliOptions);

if (cliOptions.build) {
await build(siteDir, {
config: cliOptions.config,
Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus/src/commands/start/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import openBrowser from 'react-dev-utils/openBrowser';
import {setupSiteFileWatchers} from './watcher';
import {createWebpackDevServer} from './webpack';
import {createReloadableSite} from './utils';
import {forceV4OnRemoteContainers} from '../../server/remoteContainersHook';
import type {LoadContextParams} from '../../server/site';
import type {HostPortOptions} from '../../server/getHostPort';

Expand All @@ -31,6 +32,8 @@ export async function start(
// See https://github.com/facebook/docusaurus/issues/4542
process.env.DOCUSAURUS_CURRENT_LOCALE = cliOptions.locale;

forceV4OnRemoteContainers(cliOptions);

const reloadableSite = await createReloadableSite({siteDirParam, cliOptions});

setupSiteFileWatchers(
Expand Down
27 changes: 27 additions & 0 deletions packages/docusaurus/src/server/remoteContainersHook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import logger from '@docusaurus/logger';

export function forceV4OnRemoteContainers(
userCLIConfig: OptionallyProvidedHost,
): void {
if (process.env.REMOTE_CONTAINERS === 'true') {
if (!userCLIConfig.host) {
userCLIConfig.host = '127.0.0.1';
logger.info(
'Will default to binding to IPv4 local address to better support VSCode Remote port forwarding',
);
} else {
logger.warn('VSCode Remote may not support IPv6');
}
}
}

export type OptionallyProvidedHost = {
host?: string;
};

0 comments on commit 36cc19c

Please sign in to comment.