File tree Expand file tree Collapse file tree 5 files changed +19
-2
lines changed
Expand file tree Collapse file tree 5 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,12 @@ export default defineConfig({
1818 name : 'setup' ,
1919 async configureServer ( viteDevServer ) {
2020 const context = await createDevToolsContext ( viteDevServer . config , viteDevServer )
21+ const host = viteDevServer . config . server . host === true
22+ ? '0.0.0.0'
23+ : viteDevServer . config . server . host || 'localhost'
2124 const { middleware } = await createDevToolsMiddleware ( {
2225 cwd : viteDevServer . config . root ,
26+ hostWebSocket : host ,
2327 context,
2428 } )
2529 viteDevServer . middlewares . use ( '/.devtools' , middleware )
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ export async function start(options: StartOptions) {
3636
3737 const { h3 } = await createDevToolsMiddleware ( {
3838 cwd : devtools . config . root ,
39+ hostWebSocket : host ,
3940 context : devtools . context ,
4041 } )
4142
Original file line number Diff line number Diff line change @@ -15,8 +15,14 @@ export function DevToolsServer(): Plugin {
1515 apply : 'serve' ,
1616 async configureServer ( viteDevServer ) {
1717 context = await createDevToolsContext ( viteDevServer . config , viteDevServer )
18+
19+ const host = viteDevServer . config . server . host === true
20+ ? '0.0.0.0'
21+ : viteDevServer . config . server . host || 'localhost'
22+
1823 const { middleware } = await createDevToolsMiddleware ( {
1924 cwd : viteDevServer . config . root ,
25+ hostWebSocket : host ,
2026 context,
2127 } )
2228 viteDevServer . middlewares . use ( '/.devtools/' , middleware )
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { MARK_CHECK } from './constants'
1212export interface CreateWsServerOptions {
1313 cwd : string
1414 portWebSocket ?: number
15+ hostWebSocket : string
1516 base ?: string
1617 context : DevToolsNodeContext
1718}
@@ -20,12 +21,14 @@ const ANONYMOUS_SCOPE = 'vite:anonymous:'
2021
2122export async function createWsServer ( options : CreateWsServerOptions ) {
2223 const rpcHost = options . context . rpc as unknown as RpcFunctionsHost
23- const port = options . portWebSocket ?? await getPort ( { port : 7812 , random : true } )
24+ const port = options . portWebSocket ?? await getPort ( { port : 7812 , random : true } ) !
25+ const host = options . hostWebSocket ?? 'localhost'
2426
2527 const wsClients = new Set < WebSocket > ( )
2628
2729 const preset = createWsRpcPreset ( {
28- port : port ! ,
30+ port,
31+ host,
2932 onConnected : ( ws , meta ) => {
3033 wsClients . add ( ws )
3134 console . log ( c . green `${ MARK_CHECK } Websocket client [${ meta . id } ] connected` )
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { defineRpcServerPreset } from '..'
88
99export interface WebSocketRpcServerOptions {
1010 port : number
11+ host ?: string
1112 onConnected ?: ( ws : WebSocket , meta : DevToolsNodeRpcSessionMeta ) => void
1213 onDisconnected ?: ( ws : WebSocket , meta : DevToolsNodeRpcSessionMeta ) => void
1314}
@@ -28,12 +29,14 @@ export const createWsRpcPreset: RpcServerPreset<
2829> = defineRpcServerPreset ( ( options : WebSocketRpcServerOptions ) => {
2930 const {
3031 port,
32+ host = 'localhost' ,
3133 onConnected = NOOP ,
3234 onDisconnected = NOOP ,
3335 } = options
3436
3537 const wss = new WebSocketServer ( {
3638 port,
39+ host,
3740 } )
3841
3942 return < ClientFunctions extends object , ServerFunctions extends object > (
You can’t perform that action at this time.
0 commit comments