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

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