Skip to content

Commit

Permalink
fix: use vite server config for hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
nicotu01 authored and f4562 committed Nov 29, 2024
1 parent 30ab658 commit 98d6576
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/plugins/pluginAddEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ const addEntry = ({
},
configureServer(server) {
server.httpServer?.once?.('listening', () => {
const { port } = server.config.server;
fetch(`http://localhost:${port}${devEntryPath}`).catch((e) => {});
const { port, host: hostConfig } = server.config.server;
const host = hostConfig && hostConfig !== '0.0.0.0' ? hostConfig : 'localhost';
fetch(`http://${host}:${port}${devEntryPath}`).catch((e) => {});
});
server.middlewares.use((req, res, next) => {
if (!fileName) {
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/pluginProxyRemoteEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ export default function (): Plugin {
if (id.includes(getHostAutoInitPath())) {
const options = getNormalizeModuleFederationOptions();
if (_command === 'serve') {
const host =
viteConfig.server?.host && viteConfig.server.host !== '0.0.0.0'
? viteConfig.server.host
: 'localhost';
return `
const {init} = await import("//localhost:${viteConfig.server?.port}${viteConfig.base + options.filename}")
const {init} = await import("//${host}:${viteConfig.server?.port}${viteConfig.base + options.filename}")
init()
`;
}
Expand Down

0 comments on commit 98d6576

Please sign in to comment.