Skip to content

Commit

Permalink
fix: use vite server config for hostname (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicotu01 authored Dec 3, 2024
1 parent e29dfda commit b377cc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/plugins/pluginAddEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ 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 =
typeof hostConfig === 'string' && 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 =
typeof viteConfig.server?.host === 'string' && 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 b377cc0

Please sign in to comment.