nuts / goo / files / vite.config.ts
Branch goo · default branch · all branches
vite.config.ts
| 1 | import { defineConfig, type Plugin } from 'vite' |
| 2 | import { qrcode } from 'vite-plugin-qrcode' |
| 3 | import basicSsl from '@vitejs/plugin-basic-ssl' |
| 4 | import type { IncomingMessage, ServerResponse } from 'node:http' |
| 5 | |
| 6 | function remoteLog(): Plugin { |
| 7 | return { |
| 8 | name: 'remote-log', |
| 9 | configureServer(server) { |
| 10 | server.middlewares.use( |
| 11 | '/__log', |
| 12 | (req: IncomingMessage, res: ServerResponse) => { |
| 13 | if (req.method !== 'POST') { |
| 14 | res.writeHead(405).end() |
| 15 | return |
| 16 | } |
| 17 | let body = '' |
| 18 | req.setEncoding('utf8') |
| 19 | req.on('data', (chunk: string) => { body += chunk }) |
| 20 | req.on('end', () => { |
| 21 | try { |
| 22 | const { level, msg } = JSON.parse(body) as { level: string; msg: string } |
| 23 | const prefix = '\x1b[36m[web]\x1b[0m' |
| 24 | if (level === 'error') { |
| 25 | server.config.logger.error(`${prefix} ${msg}`) |
| 26 | } else { |
| 27 | server.config.logger.info(`${prefix} ${msg}`) |
| 28 | } |
| 29 | } catch { /* malformed – ignore */ } |
| 30 | res.writeHead(204).end() |
| 31 | }) |
| 32 | } |
| 33 | ) |
| 34 | }, |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export default defineConfig({ |
| 39 | base: './', |
| 40 | build: { |
| 41 | outDir: 'dist', |
| 42 | }, |
| 43 | server: { |
| 44 | host: true, // listen on 0.0.0.0 so the phone can reach it |
| 45 | }, |
| 46 | plugins: [remoteLog(), basicSsl(), qrcode()], |
| 47 | }) |