MCPcopy Create free account
hub / github.com/TanStack/devtools / configureServer

Function configureServer

packages/devtools-vite/src/plugin.ts:179–320  ·  view source on GitHub ↗
(server)

Source from the content-addressed store, hash-verified

177 res: ServerResponse
178 id: number
179 }> = []
180 let sseClientId = 0
181 const consolePipingEnabled = consolePipingConfig.enabled ?? true
182
183 server.middlewares.use((req, res, next) =>
184 handleDevToolsRequest(req, res, next, {
185 onOpenSource: (parsedData) => {
186 const { data, routine } = parsedData
187 if (routine === 'open-source') {
188 return handleOpenSource({
189 data: { type: data.type, data },
190 openInEditor,
191 })
192 }
193 return
194 },
195 ...(consolePipingEnabled
196 ? {
197 onConsolePipe: (entries) => {
198 for (const entry of entries) {
199 const prefix = chalk.cyan('[Client]')
200 const logMethod =
201 originalConsole[entry.level as ConsoleLevel] ??
202 // log exists in consolePipingLevels
203 originalConsole.log!
204
205 const cleanedArgs = stripEnhancedLogPrefix(
206 entry.args,
207 (loc) => chalk.gray(loc),
208 )
209 logMethod(prefix, ...cleanedArgs)
210 }
211 },
212 onConsolePipeSSE: (res, req) => {
213 res.setHeader('Content-Type', 'text/event-stream')
214 res.setHeader('Cache-Control', 'no-cache')
215 res.setHeader('Connection', 'keep-alive')
216 res.setHeader('Access-Control-Allow-Origin', '*')
217 res.flushHeaders()
218
219 const clientId = ++sseClientId
220 sseClients.push({ res, id: clientId })
221
222 req.on('close', () => {
223 const index = sseClients.findIndex(
224 (c) => c.id === clientId,
225 )
226 if (index !== -1) {
227 sseClients.splice(index, 1)
228 }
229 })
230 },
231 onServerConsolePipe: (entries) => {
232 try {
233 const data = JSON.stringify({
234 entries: entries.map((e) => ({
235 level: e.level,
236 args: e.args,

Callers 1

index.test.tsFile · 0.85

Calls 12

startMethod · 0.95
handleOpenSourceFunction · 0.90
stripEnhancedLogPrefixFunction · 0.90
readPackageJsonFunction · 0.90
emitOutdatedDepsFunction · 0.90
installPackageFunction · 0.90
addPluginToDevtoolsFunction · 0.90
injectPluginIntoFileFunction · 0.90
onMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected