diff options
Diffstat (limited to 'subprojects/frontend/vite.config.ts')
-rw-r--r-- | subprojects/frontend/vite.config.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/subprojects/frontend/vite.config.ts b/subprojects/frontend/vite.config.ts index e690d005..526ea541 100644 --- a/subprojects/frontend/vite.config.ts +++ b/subprojects/frontend/vite.config.ts | |||
@@ -30,6 +30,7 @@ const apiPort = portNumberOrElse('API_PORT', 1312); | |||
30 | const apiSecure = apiPort === 443; | 30 | const apiSecure = apiPort === 443; |
31 | const publicHost = process.env.PUBLIC_HOST || listenHost; | 31 | const publicHost = process.env.PUBLIC_HOST || listenHost; |
32 | const publicPort = portNumberOrElse('PUBLIC_PORT', listenPort); | 32 | const publicPort = portNumberOrElse('PUBLIC_PORT', listenPort); |
33 | const publicSecure = publicPort === 443; | ||
33 | 34 | ||
34 | const { name: packageName, version: packageVersion } = JSON.parse( | 35 | const { name: packageName, version: packageVersion } = JSON.parse( |
35 | readFileSync(path.join(thisDir, 'package.json'), 'utf8'), | 36 | readFileSync(path.join(thisDir, 'package.json'), 'utf8'), |
@@ -56,6 +57,23 @@ const minifyPlugin: PluginOption = { | |||
56 | }, | 57 | }, |
57 | }; | 58 | }; |
58 | 59 | ||
60 | const backendConfigPlugin: PluginOption = { | ||
61 | name: 'backend-config', | ||
62 | configureServer(server) { | ||
63 | const protocol = publicSecure ? 'wss' : 'ws'; | ||
64 | const webSocketURL = `${protocol}://${publicHost}:${publicPort}/xtext-service`; | ||
65 | const config = JSON.stringify({ webSocketURL }); | ||
66 | server.middlewares.use((req, res, next) => { | ||
67 | if (req.url === '/config.json') { | ||
68 | res.setHeader('Content-Type', 'application/json'); | ||
69 | res.end(config); | ||
70 | } else { | ||
71 | next(); | ||
72 | } | ||
73 | }); | ||
74 | }, | ||
75 | }; | ||
76 | |||
59 | export default defineConfig({ | 77 | export default defineConfig({ |
60 | logLevel: 'info', | 78 | logLevel: 'info', |
61 | mode, | 79 | mode, |
@@ -63,6 +81,7 @@ export default defineConfig({ | |||
63 | cacheDir: path.join(thisDir, 'build/vite/cache'), | 81 | cacheDir: path.join(thisDir, 'build/vite/cache'), |
64 | plugins: [ | 82 | plugins: [ |
65 | minifyPlugin, | 83 | minifyPlugin, |
84 | backendConfigPlugin, | ||
66 | react(), | 85 | react(), |
67 | injectPreload({ | 86 | injectPreload({ |
68 | files: [ | 87 | files: [ |
@@ -90,6 +109,12 @@ export default defineConfig({ | |||
90 | ], | 109 | ], |
91 | dontCacheBustURLsMatching: /\.(?:css|js|woff2?)$/, | 110 | dontCacheBustURLsMatching: /\.(?:css|js|woff2?)$/, |
92 | navigateFallbackDenylist: [/^\/xtext-service/], | 111 | navigateFallbackDenylist: [/^\/xtext-service/], |
112 | runtimeCaching: [ | ||
113 | { | ||
114 | urlPattern: 'config.json', | ||
115 | handler: 'StaleWhileRevalidate', | ||
116 | }, | ||
117 | ], | ||
93 | }, | 118 | }, |
94 | includeAssets: ['apple-touch-icon.png', 'favicon.svg', 'mask-icon.svg'], | 119 | includeAssets: ['apple-touch-icon.png', 'favicon.svg', 'mask-icon.svg'], |
95 | manifest: { | 120 | manifest: { |