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(builder-shared): The http://0.0.0.0:port can't visit in windows #3443

Merged
merged 7 commits into from Apr 17, 2023
6 changes: 6 additions & 0 deletions .changeset/blue-kiwis-raise.md
@@ -0,0 +1,6 @@
---
'@modern-js/builder-shared': patch
---

fix: The http://0.0.0.0:port can't visit in windows, we shouldn't set publicPath as `//0.0.0.0:${port}/`;
fix: 在 windows 里不能正常访问 http://0.0.0.0:port,我们不应该将 publicPath 设置成 `//0.0.0.0:${port}`
11 changes: 10 additions & 1 deletion packages/builder/builder-shared/src/apply/output.ts
Expand Up @@ -82,7 +82,16 @@ function getPublicPath({
} else if (dev.assetPrefix === true) {
const hostname = context.devServer?.hostname || DEFAULT_DEV_HOST;
const port = context.devServer?.port || DEFAULT_PORT;
publicPath = `//${hostname}:${port}/`;
if (hostname === DEFAULT_DEV_HOST) {
const localHostname = `127.0.0.1`;
chenjiahan marked this conversation as resolved.
Show resolved Hide resolved
// If user not specify the hostname, it would use 0.0.0.0
// The http://0.0.0.0:port can't visit in windows, so we shouldn't set publicPath as `//0.0.0.0:${port}/`;
// Relative to docs:
// - https://github.com/quarkusio/quarkus/issues/12246
publicPath = `//${localHostname}:${port}/`;
} else {
publicPath = `//${hostname}:${port}/`;
}
}

return addTrailingSlash(publicPath);
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/asset-prefix/test/index.test.ts
@@ -1,9 +1,9 @@
import path from 'path';
import { readFileSync } from 'fs';
import { Page } from 'puppeteer';
import { DEFAULT_DEV_HOST } from '@modern-js/utils';
import { launchApp, killApp } from '../../../utils/modernTestUtils';

const DEFAULT_DEV_HOST = '127.0.0.1';
declare const page: Page;

const fixtures = path.resolve(__dirname, '../fixtures');
Expand Down