Skip to content

Commit dd55a90

Browse files
committed
refactor(electron): cleanup
1 parent c34ac3c commit dd55a90

File tree

1 file changed

+1
-39
lines changed

1 file changed

+1
-39
lines changed

packages/electron/src/serve.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { spawn } from 'child_process'
2-
import type { AddressInfo } from 'net'
32
import {
43
type Plugin,
54
type ViteDevServer,
@@ -14,46 +13,9 @@ import {
1413
resolveRuntime,
1514
resolveBuildConfig,
1615
checkPkgMain,
16+
resolveEnv,
1717
} from './config'
1818

19-
export const loopbackHosts = new Set([
20-
'localhost',
21-
'127.0.0.1',
22-
'::1',
23-
'0000:0000:0000:0000:0000:0000:0000:0001'
24-
])
25-
26-
export const wildcardHosts = new Set([
27-
'0.0.0.0',
28-
'::',
29-
'0000:0000:0000:0000:0000:0000:0000:0000'
30-
])
31-
32-
function resolveHostname(hostname: string) {
33-
return loopbackHosts.has(hostname) || wildcardHosts.has(hostname) ? 'localhost' : hostname
34-
}
35-
36-
function resolveEnv(server: ViteDevServer) {
37-
const addressInfo = server.httpServer.address()
38-
const isAddressInfo = (x: any): x is AddressInfo => x?.address
39-
40-
if (isAddressInfo(addressInfo)) {
41-
const { address, port } = addressInfo
42-
const host = resolveHostname(address)
43-
44-
const options = server.config.server
45-
const protocol = options.https ? 'https' : 'http'
46-
const devBase = server.config.base
47-
48-
const path = typeof options.open === 'string' ? options.open : devBase
49-
const url = path.startsWith('http')
50-
? path
51-
: `${protocol}://${host}:${port}${path}`
52-
53-
return { url, host, port }
54-
}
55-
}
56-
5719
/**
5820
* Custom start plugin
5921
*/

0 commit comments

Comments
 (0)