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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions .changeset/blue-kiwis-raise.md
Original file line number Diff line number Diff line change
@@ -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}`
8 changes: 7 additions & 1 deletion packages/builder/builder-shared/src/apply/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ 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) {
GiveMe-A-Name marked this conversation as resolved.
Show resolved Hide resolved
// If user not specify the hostname, it would use DEFAULT_DEV_HOST(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 = `//${hostname}:${port}/`;
}
}

return addTrailingSlash(publicPath);
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/asset-prefix/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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';

declare const page: Page;
Expand All @@ -18,7 +17,7 @@ describe('asset prefix', () => {
path.join(appDir, 'dist/html/main/index.html'),
'utf-8',
);
expect(HTML.includes(`//${DEFAULT_DEV_HOST}:3333/static/js/`)).toBeTruthy();
expect(HTML.includes(`/static/js/`)).toBeTruthy();

killApp(app);
});
Expand All @@ -27,7 +26,7 @@ describe('asset prefix', () => {
const appDir = path.resolve(fixtures, 'dev-asset-prefix');

const app = await launchApp(appDir);
const expected = `//${DEFAULT_DEV_HOST}:3333`;
const expected = '';

const mainJs = readFileSync(
path.join(appDir, 'dist/static/js/main.js'),
Expand All @@ -38,7 +37,7 @@ describe('asset prefix', () => {
mainJs.includes(`window.__assetPrefix__ = '${expected}';`),
).toBeTruthy();

await page.goto(`http:${expected}`);
await page.goto(`http://localhost:3333`);

const assetPrefix = await page.evaluate(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down