diff options
author | 2022-12-09 23:49:07 +0100 | |
---|---|---|
committer | 2022-12-11 12:18:43 +0100 | |
commit | 280a3fab74348697429b7bab56b3436968113d79 (patch) | |
tree | e1603153db18f7f35c1bcceb03462409f75002db /subprojects/frontend/config/backendConfigVitePlugin.ts | |
parent | refactor(frontend): lazy load XtextClient (diff) | |
download | refinery-280a3fab74348697429b7bab56b3436968113d79.tar.gz refinery-280a3fab74348697429b7bab56b3436968113d79.tar.zst refinery-280a3fab74348697429b7bab56b3436968113d79.zip |
refactor(frontend): split vite config
Also introduces tsconfig.shared.json to keep track of source files used
both and build time and in the browser.
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'; | ||