1- import type { DevToolsNodeContext , DevToolsNodeRpcSessionMeta } from '@vitejs/devtools-kit'
1+ import type { DevToolsNodeRpcSessionMeta } from '@vitejs/devtools-kit'
22import type { BirpcGroup , BirpcOptions , ChannelOptions } from 'birpc'
3+ import type { IncomingMessage } from 'node:http'
34import type { WebSocket } from 'ws'
45import type { RpcServerPreset } from '..'
5- import process from 'node:process'
66import { parse , stringify } from 'structured-clone-es'
77import { WebSocketServer } from 'ws'
88import { defineRpcServerPreset } from '..'
9- import { getInternalContext } from '../../../../core/src/node/context-internal'
109
1110export interface WebSocketRpcServerOptions {
1211 port : number
1312 host ?: string
14- context : DevToolsNodeContext
15- onConnected ?: ( ws : WebSocket , meta : DevToolsNodeRpcSessionMeta ) => void
13+ onConnected ?: ( ws : WebSocket , req : IncomingMessage , meta : DevToolsNodeRpcSessionMeta ) => void
1614 onDisconnected ?: ( ws : WebSocket , meta : DevToolsNodeRpcSessionMeta ) => void
1715}
1816
@@ -35,16 +33,8 @@ export const createWsRpcPreset: RpcServerPreset<
3533 host = 'localhost' ,
3634 onConnected = NOOP ,
3735 onDisconnected = NOOP ,
38- context,
3936 } = options
4037
41- const isClientAuthDisabled = context . mode === 'build' || context . viteConfig . devtools ?. clientAuth === false || process . env . VITE_DEVTOOLS_DISABLE_CLIENT_AUTH === 'true'
42- if ( isClientAuthDisabled ) {
43- console . warn ( '[Vite DevTools] Client authentication is disabled. Any browser can connect to the devtools and access to your server and filesystem.' )
44- }
45-
46- const internal = getInternalContext ( context )
47-
4838 const wss = new WebSocketServer ( {
4939 port,
5040 host,
@@ -60,21 +50,9 @@ export const createWsRpcPreset: RpcServerPreset<
6050 } = options ?? { }
6151
6252 wss . on ( 'connection' , ( ws , req ) => {
63- const url = new URL ( req . url ?? '' , 'http://localhost' )
64- const authId = url . searchParams . get ( 'vite_devtools_auth_id' ) ?? undefined
65- let isTrusted = false
66- if ( isClientAuthDisabled ) {
67- isTrusted = true
68- }
69- else if ( authId && internal . storage . auth . get ( ) . trusted [ authId ] ) {
70- isTrusted = true
71- }
72-
7353 const meta : DevToolsNodeRpcSessionMeta = {
7454 id : id ++ ,
7555 ws,
76- isTrusted,
77- clientAuthId : authId ,
7856 }
7957
8058 const channel : ChannelOptions = {
@@ -105,7 +83,7 @@ export const createWsRpcPreset: RpcServerPreset<
10583 } )
10684 onDisconnected ( ws , meta )
10785 } )
108- onConnected ( ws , meta )
86+ onConnected ( ws , req , meta )
10987 } )
11088 }
11189} )
0 commit comments