| 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({ |