collin/mahjong
95126effc7a7d363a91f49efda2491719e116ecf / vite.config.ts
| 1 | import { defineConfig, type Plugin } from 'vite' |
| 2 | import react from '@vitejs/plugin-react' |
| 3 | import { attachRooms } from './server/rooms.ts' |
| 4 | |
| 5 | // The room relay rides vite's own http server, so `npm run dev` (and |
| 6 | // `npm run preview`) is the whole stack — the client finds it at /ws on the |
| 7 | // same origin, exactly where server/index.ts puts it in production. |
| 8 | const roomRelay = (): Plugin => ({ |
| 9 | name: 'room-relay', |
| 10 | configureServer(s) { |
| 11 | if (s.httpServer) attachRooms(s.httpServer) |
| 12 | }, |
| 13 | configurePreviewServer(s) { |
| 14 | if (s.httpServer) attachRooms(s.httpServer) |
| 15 | }, |
| 16 | }) |
| 17 | |
| 18 | // https://vite.dev/config/ |
| 19 | export default defineConfig({ |
| 20 | plugins: [react(), roomRelay()], |
| 21 | // Served happily from under any path, not just a domain root — so every |
| 22 | // built URL has to be relative to the page. |
| 23 | base: './', |
| 24 | // portless hands us PORT/HOST; vite doesn't read them on its own |
| 25 | server: { |
| 26 | port: process.env.PORT ? Number(process.env.PORT) : undefined, |
| 27 | host: process.env.HOST || undefined, |
| 28 | // Tunnels and LAN names have to get past vite's Host check, or every |
| 29 | // phone that scans the QR meets a 403. |
| 30 | allowedHosts: [ |
| 31 | '.vibe.richardscollin.com', // rsgrok, the house tunnel (~/Code/ngrok) |
| 32 | '.ngrok-free.dev', |
| 33 | '.ngrok.app', |
| 34 | '.ngrok.dev', |
| 35 | '.local', |
| 36 | '.localhost', |
| 37 | ], |
| 38 | }, |
| 39 | }) |