|
1 | 1 | import { defineConfig } from 'vite' |
2 | 2 | import react from '@vitejs/plugin-react' |
3 | 3 | import { VitePWA } from 'vite-plugin-pwa' |
| 4 | +import fs from 'fs' |
| 5 | +import path from 'path' |
| 6 | + |
| 7 | +const certDir = path.resolve(__dirname, 'certs') |
| 8 | +const certPath = path.join(certDir, 'localhost.pem') |
| 9 | +const keyPath = path.join(certDir, 'localhost-key.pem') |
| 10 | + |
| 11 | +let httpsOptions = false |
| 12 | +try { |
| 13 | + if (fs.existsSync(certPath) && fs.existsSync(keyPath)) { |
| 14 | + httpsOptions = { |
| 15 | + cert: fs.readFileSync(certPath), |
| 16 | + key: fs.readFileSync(keyPath) |
| 17 | + } |
| 18 | + console.log('[vite] Using HTTPS certs for dev server') |
| 19 | + } else { |
| 20 | + console.warn('[vite] No HTTPS certs found — run `npm run generate-cert` to create them') |
| 21 | + } |
| 22 | +} catch (e) { |
| 23 | + console.warn('[vite] Error reading HTTPS certs:', e.message) |
| 24 | +} |
4 | 25 |
|
5 | 26 | export default defineConfig({ |
6 | | - base: process.env.VITE_BASE_PATH || '/', |
7 | | - plugins: [ |
8 | | - react(), |
9 | | - VitePWA({ |
10 | | - registerType: 'autoUpdate', |
11 | | - workbox: { |
12 | | - globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'], |
13 | | - navigateFallback: '/offline.html', |
14 | | - navigateFallbackDenylist: [/^\/api\//], |
15 | | - runtimeCaching: [ |
16 | | - { |
17 | | - urlPattern: /^https:\/\/0\.peerjs\.com\//, |
18 | | - handler: 'NetworkFirst', |
19 | | - options: { |
20 | | - cacheName: 'peerjs-cache', |
21 | | - expiration: { |
22 | | - maxEntries: 10, |
23 | | - maxAgeSeconds: 60 * 60 * 24 // 24 hours |
24 | | - } |
25 | | - } |
26 | | - }, |
27 | | - { |
28 | | - urlPattern: /^https:\/\/api\.qrserver\.com\//, |
29 | | - handler: 'CacheFirst', |
30 | | - options: { |
31 | | - cacheName: 'qr-cache', |
32 | | - expiration: { |
33 | | - maxEntries: 50, |
34 | | - maxAgeSeconds: 60 * 60 * 24 * 7 // 7 days |
35 | | - } |
36 | | - } |
37 | | - } |
38 | | - ] |
39 | | - }, |
40 | | - manifest: { |
41 | | - name: 'Peer P2P Voice Chat', |
42 | | - short_name: 'PeerChat', |
43 | | - description: 'Local Wi-Fi P2P voice chat using WebRTC (PeerJS)', |
44 | | - theme_color: '#0f172a', |
45 | | - background_color: '#0f172a', |
46 | | - display: 'standalone', |
47 | | - orientation: 'portrait-primary', |
48 | | - scope: '/', |
49 | | - start_url: '/', |
50 | | - lang: 'en', |
51 | | - categories: ['communication', 'social'], |
52 | | - icons: [ |
53 | | - { |
54 | | - src: 'pwa-192x192.png', |
55 | | - sizes: '192x192', |
56 | | - type: 'image/png', |
57 | | - purpose: 'any maskable' |
58 | | - }, |
59 | | - { |
60 | | - src: 'pwa-512x512.png', |
61 | | - sizes: '512x512', |
62 | | - type: 'image/png', |
63 | | - purpose: 'any maskable' |
64 | | - }, |
65 | | - { |
66 | | - src: 'apple-touch-icon.png', |
67 | | - sizes: '180x180', |
68 | | - type: 'image/png' |
69 | | - } |
70 | | - ], |
71 | | - shortcuts: [ |
72 | | - { |
73 | | - name: 'Start Voice Chat', |
74 | | - short_name: 'Voice Chat', |
75 | | - description: 'Start a new voice chat session', |
76 | | - url: '/?action=call', |
77 | | - icons: [ |
78 | | - { |
79 | | - src: 'pwa-192x192.png', |
80 | | - sizes: '192x192' |
81 | | - } |
82 | | - ] |
83 | | - } |
84 | | - ] |
85 | | - }, |
86 | | - devOptions: { |
87 | | - enabled: true |
| 27 | + base: process.env.VITE_BASE_PATH || '/', |
| 28 | + plugins: [ |
| 29 | + react(), |
| 30 | + VitePWA({ |
| 31 | + registerType: 'autoUpdate', |
| 32 | + workbox: { |
| 33 | + globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'], |
| 34 | + navigateFallback: '/offline.html', |
| 35 | + navigateFallbackDenylist: [/^\\/api\\//], |
| 36 | + runtimeCaching: [ |
| 37 | + { |
| 38 | + urlPattern: /^https:\\/\\/0\\.peerjs\\.com\\//, |
| 39 | + handler: 'NetworkFirst', |
| 40 | + options: { |
| 41 | + cacheName: 'peerjs-cache', |
| 42 | + expiration: { |
| 43 | + maxEntries: 10, |
| 44 | + maxAgeSeconds: 60 * 60 * 24 |
| 45 | + } |
88 | 46 | } |
89 | | - }) |
90 | | - ], |
91 | | - server: { |
92 | | - host: true, |
93 | | - port: 5173 |
94 | | - } |
| 47 | + }, |
| 48 | + { |
| 49 | + urlPattern: /^https:\\/\\/api\\.qrserver\\.com\\//, |
| 50 | + handler: 'CacheFirst', |
| 51 | + options: { |
| 52 | + cacheName: 'qr-cache', |
| 53 | + expiration: { |
| 54 | + maxEntries: 50, |
| 55 | + maxAgeSeconds: 60 * 60 * 24 * 7 |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + ] |
| 60 | + }, |
| 61 | + manifest: { |
| 62 | + name: 'Peer P2P Voice Chat', |
| 63 | + short_name: 'PeerChat', |
| 64 | + description: 'Local Wi-Fi P2P voice chat using WebRTC (PeerJS)', |
| 65 | + theme_color: '#0f172a', |
| 66 | + background_color: '#0f172a', |
| 67 | + display: 'standalone', |
| 68 | + orientation: 'portrait-primary', |
| 69 | + scope: '/', |
| 70 | + start_url: '/', |
| 71 | + lang: 'en', |
| 72 | + categories: ['communication', 'social'], |
| 73 | + icons: [ |
| 74 | + { |
| 75 | + src: 'pwa-192x192.png', |
| 76 | + sizes: '192x192', |
| 77 | + type: 'image/png', |
| 78 | + purpose: 'any maskable' |
| 79 | + }, |
| 80 | + { |
| 81 | + src: 'pwa-512x512.png', |
| 82 | + sizes: '512x512', |
| 83 | + type: 'image/png', |
| 84 | + purpose: 'any maskable' |
| 85 | + }, |
| 86 | + { |
| 87 | + src: 'apple-touch-icon.png', |
| 88 | + sizes: '180x180', |
| 89 | + type: 'image/png' |
| 90 | + } |
| 91 | + ], |
| 92 | + shortcuts: [ |
| 93 | + { |
| 94 | + name: 'Start Voice Chat', |
| 95 | + short_name: 'Voice Chat', |
| 96 | + description: 'Start a new voice chat session', |
| 97 | + url: '/?action=call', |
| 98 | + icons: [ |
| 99 | + { |
| 100 | + src: 'pwa-192x192.png', |
| 101 | + sizes: '192x192' |
| 102 | + } |
| 103 | + ] |
| 104 | + } |
| 105 | + ] |
| 106 | + }, |
| 107 | + devOptions: { |
| 108 | + enabled: true |
| 109 | + } |
| 110 | + }) |
| 111 | + ], |
| 112 | + server: { |
| 113 | + host: true, |
| 114 | + port: 5173, |
| 115 | + https: httpsOptions |
| 116 | + } |
95 | 117 | }) |
0 commit comments