Skip to content

Commit 0eea33a

Browse files
nicotu01f4562
authored and
f4562
committed
fix: use vite server config for hostname
1 parent 30ab658 commit 0eea33a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/plugins/pluginAddEntry.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ const addEntry = ({
4040
},
4141
configureServer(server) {
4242
server.httpServer?.once?.('listening', () => {
43-
const { port } = server.config.server;
44-
fetch(`http://localhost:${port}${devEntryPath}`).catch((e) => {});
43+
const { port, host: hostConfig } = server.config.server;
44+
const host =
45+
typeof hostConfig === 'string' && hostConfig !== '0.0.0.0' ? hostConfig : 'localhost';
46+
fetch(`http://${host}:${port}${devEntryPath}`).catch((e) => {});
4547
});
4648
server.middlewares.use((req, res, next) => {
4749
if (!fileName) {

src/plugins/pluginProxyRemoteEntry.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ export default function (): Plugin {
5656
if (id.includes(getHostAutoInitPath())) {
5757
const options = getNormalizeModuleFederationOptions();
5858
if (_command === 'serve') {
59+
const host =
60+
typeof viteConfig.server?.host === 'string' && viteConfig.server.host !== '0.0.0.0'
61+
? viteConfig.server.host
62+
: 'localhost';
5963
return `
60-
const {init} = await import("//localhost:${viteConfig.server?.port}${viteConfig.base + options.filename}")
64+
const {init} = await import("//${host}:${viteConfig.server?.port}${viteConfig.base + options.filename}")
6165
init()
6266
`;
6367
}

0 commit comments

Comments
 (0)