add file logging via Vite middleware to ZoomTestScene

Vite dev server gets a /api/log middleware (POST appends to
game-test.log, DELETE clears it). ZoomTestScene writes a zoom event
with before/after state on every scroll, plus a full snapshot every
2 seconds. Log entries are newline-delimited JSON.
This commit is contained in:
2026-03-21 11:19:54 +00:00
parent 007d5b3fee
commit 9b6341fe46
4 changed files with 163 additions and 9 deletions

View File

@@ -1,11 +1,39 @@
import { defineConfig } from 'vite'
import { resolve } from 'path'
import fs from 'fs'
const LOG_FILE = resolve(__dirname, 'game-test.log')
export default defineConfig({
server: {
port: 3000,
host: true
host: true,
},
plugins: [
{
name: 'game-logger',
configureServer(server) {
server.middlewares.use('/api/log', (req, res) => {
if (req.method === 'POST') {
let body = ''
req.on('data', chunk => { body += chunk })
req.on('end', () => {
fs.appendFileSync(LOG_FILE, body + '\n', 'utf8')
res.writeHead(200)
res.end('ok')
})
} else if (req.method === 'DELETE') {
fs.writeFileSync(LOG_FILE, '', 'utf8')
res.writeHead(200)
res.end('cleared')
} else {
res.writeHead(405)
res.end()
}
})
},
},
],
build: {
outDir: 'dist',
assetsInlineLimit: 0,