MCPcopy Index your code
hub / github.com/TanStack/db / wasmHandler

Function wasmHandler

examples/react/offline-transactions/vite.config.ts:93–118  ·  view source on GitHub ↗
(req: any, res: any, next: () => void)

Source from the content-addressed store, hash-verified

91 name: `serve-wasm-files`,
92 configureServer(server: any) {
93 const wasmHandler = (req: any, res: any, next: () => void) => {
94 // Strip query string before checking extension
95 const urlWithoutQuery = (req.url ?? ``).split(`?`)[0]
96 if (!urlWithoutQuery.endsWith(`.wasm`)) {
97 return next()
98 }
99
100 // Handle /@fs/ paths used by Vite for serving node_modules files
101 const fsPrefix = `/@fs`
102 let filePath: string | undefined
103 if (urlWithoutQuery.startsWith(fsPrefix)) {
104 filePath = urlWithoutQuery.slice(fsPrefix.length)
105 }
106
107 if (!filePath || !fs.existsSync(filePath)) {
108 return next()
109 }
110
111 const content = fs.readFileSync(filePath)
112 res.writeHead(200, {
113 'Content-Type': `application/wasm`,
114 'Content-Length': content.byteLength,
115 'Cache-Control': `no-cache`,
116 })
117 res.end(content)
118 }
119
120 // Prepend to the middleware stack so it runs before TanStack Start
121 server.middlewares.stack.unshift({

Callers

nothing calls this directly

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected