diff options
Diffstat (limited to 'subprojects/frontend/config/backendConfigVitePlugin.ts')
-rw-r--r-- | subprojects/frontend/config/backendConfigVitePlugin.ts | 27 |
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 @@ | |||
1 | import type { PluginOption } from 'vite'; | ||
2 | |||
3 | import type BackendConfig from '../src/xtext/BackendConfig'; | ||
4 | import { ENDPOINT } from '../src/xtext/BackendConfig'; | ||
5 | |||
6 | export 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 | |||
26 | export type { default as BackendConfig } from '../src/xtext/BackendConfig'; | ||
27 | export { ENDPOINT as CONFIG_ENDPOINT } from '../src/xtext/BackendConfig'; | ||