aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/config/backendConfigVitePlugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/config/backendConfigVitePlugin.ts')
-rw-r--r--subprojects/frontend/config/backendConfigVitePlugin.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/subprojects/frontend/config/backendConfigVitePlugin.ts b/subprojects/frontend/config/backendConfigVitePlugin.ts
new file mode 100644
index 00000000..7a6bc3db
--- /dev/null
+++ b/subprojects/frontend/config/backendConfigVitePlugin.ts
@@ -0,0 +1,27 @@
1import type { PluginOption } from 'vite';
2
3import type BackendConfig from '../src/xtext/BackendConfig';
4import { ENDPOINT } from '../src/xtext/BackendConfig';
5
6export default function backendConfigVitePlugin(
7 backendConfig: BackendConfig,
8): PluginOption {
9 return {
10 name: 'backend-config',
11 apply: 'serve',
12 configureServer(server) {
13 const config = JSON.stringify(backendConfig);
14 server.middlewares.use((req, res, next) => {
15 if (req.url === `/${ENDPOINT}`) {
16 res.setHeader('Content-Type', 'application/json');
17 res.end(config);
18 } else {
19 next();
20 }
21 });
22 },
23 };
24}
25
26export type { default as BackendConfig } from '../src/xtext/BackendConfig';
27export { ENDPOINT as CONFIG_ENDPOINT } from '../src/xtext/BackendConfig';