fix: ELECTRON_RENDERER_URL is incorrect
This commit is contained in:
parent
c71d5aa661
commit
c568348fc9
|
@ -2,7 +2,7 @@ import { spawn } from 'child_process'
|
||||||
import { createServer as ViteCreateServer, build as viteBuild, createLogger } from 'vite'
|
import { createServer as ViteCreateServer, build as viteBuild, createLogger } from 'vite'
|
||||||
import colors from 'picocolors'
|
import colors from 'picocolors'
|
||||||
import { InlineConfig, resolveConfig } from './config'
|
import { InlineConfig, resolveConfig } from './config'
|
||||||
import { ensureElectronEntryFile, getElectronPath } from './utils'
|
import { ensureElectronEntryFile, getElectronPath, resolveHostname } from './utils'
|
||||||
|
|
||||||
export async function createServer(inlineConfig: InlineConfig = {}): Promise<void> {
|
export async function createServer(inlineConfig: InlineConfig = {}): Promise<void> {
|
||||||
const config = await resolveConfig(inlineConfig, 'serve', 'development')
|
const config = await resolveConfig(inlineConfig, 'serve', 'development')
|
||||||
|
@ -39,7 +39,7 @@ export async function createServer(inlineConfig: InlineConfig = {}): Promise<voi
|
||||||
const conf = server.config.server
|
const conf = server.config.server
|
||||||
|
|
||||||
const protocol = conf.https ? 'https:' : 'http:'
|
const protocol = conf.https ? 'https:' : 'http:'
|
||||||
const host = conf.host || 'localhost'
|
const host = resolveHostname(conf.host)
|
||||||
const port = conf.port
|
const port = conf.port
|
||||||
process.env.ELECTRON_RENDERER_URL = `${protocol}//${host}:${port}`
|
process.env.ELECTRON_RENDERER_URL = `${protocol}//${host}:${port}`
|
||||||
|
|
||||||
|
|
|
@ -37,3 +37,9 @@ export function getElectronPath(): string {
|
||||||
throw new Error('Electron uninstall')
|
throw new Error('Electron uninstall')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const wildcardHosts = new Set(['0.0.0.0', '::', '0000:0000:0000:0000:0000:0000:0000:0000'])
|
||||||
|
|
||||||
|
export function resolveHostname(optionsHost: string | boolean | undefined): string {
|
||||||
|
return typeof optionsHost === 'string' && !wildcardHosts.has(optionsHost) ? optionsHost : 'localhost'
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue