(args?: TanStackDevtoolsViteConfig)
| 109 | // Custom server is only needed in development for piping events to the client |
| 110 | return config.mode === 'development' |
| 111 | }, |
| 112 | async configureServer(server) { |
| 113 | if (serverBusEnabled) { |
| 114 | const preferredPort = args?.eventBusConfig?.port ?? 4206 |
| 115 | const isHttps = !!server.config.server.https |
| 116 | const serverHost = |
| 117 | typeof server.config.server.host === 'string' |
| 118 | ? server.config.server.host |
| 119 | : 'localhost' |
| 120 | |
| 121 | devtoolsProtocol = isHttps ? 'https' : 'http' |
| 122 | devtoolsHost = serverHost |
| 123 | |
| 124 | const bus = new ServerEventBus({ |
| 125 | ...args?.eventBusConfig, |
| 126 | port: preferredPort, |
| 127 | host: serverHost, |
| 128 | // When HTTPS is enabled, piggyback on Vite's server |
| 129 | // so WebSocket/SSE connections share the same TLS certificate |
| 130 | ...(isHttps && server.httpServer |
| 131 | ? { httpServer: server.httpServer } |
| 132 | : {}), |
| 133 | }) |
| 134 | // start() now handles EADDRINUSE and returns the actual port |
| 135 | devtoolsPort = await bus.start() |
| 136 | if ((server as any).environments) { |
| 137 | const teardownBridge = wireRuntimeBridgeChannels( |
| 138 | server, |
| 139 | () => globalThis.__TANSTACK_EVENT_TARGET__, |
| 140 | ) |
| 141 | server.httpServer?.on('close', teardownBridge) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | server.middlewares.use((req, _res, next) => { |
| 146 | if (req.socket.localPort && req.socket.localPort !== port) { |
| 147 | port = req.socket.localPort |
| 148 | } |
| 149 | next() |
| 150 | }) |
| 151 | if (server.config.server.port) { |
| 152 | port = server.config.server.port |
| 153 | } |
| 154 | |
| 155 | server.httpServer?.on('listening', () => { |
| 156 | port = server.config.server.port |
| 157 | }) |
| 158 | |
| 159 | const editor = args?.editor ?? DEFAULT_EDITOR_CONFIG |
| 160 | const openInEditor: EditorConfig['open'] = async ( |
| 161 | path, |
| 162 | lineNum, |
| 163 | columnNum, |
| 164 | ) => { |
| 165 | if (!path) { |
| 166 | return |
| 167 | } |
| 168 | await editor.open(path, lineNum, columnNum) |
no outgoing calls
no test coverage detected