From 280a3fab74348697429b7bab56b3436968113d79 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 9 Dec 2022 23:49:07 +0100 Subject: 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. --- .../frontend/config/backendConfigVitePlugin.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 subprojects/frontend/config/backendConfigVitePlugin.ts (limited to 'subprojects/frontend/config/backendConfigVitePlugin.ts') 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 @@ +import type { PluginOption } from 'vite'; + +import type BackendConfig from '../src/xtext/BackendConfig'; +import { ENDPOINT } from '../src/xtext/BackendConfig'; + +export default function backendConfigVitePlugin( + backendConfig: BackendConfig, +): PluginOption { + return { + name: 'backend-config', + apply: 'serve', + configureServer(server) { + const config = JSON.stringify(backendConfig); + server.middlewares.use((req, res, next) => { + if (req.url === `/${ENDPOINT}`) { + res.setHeader('Content-Type', 'application/json'); + res.end(config); + } else { + next(); + } + }); + }, + }; +} + +export type { default as BackendConfig } from '../src/xtext/BackendConfig'; +export { ENDPOINT as CONFIG_ENDPOINT } from '../src/xtext/BackendConfig'; -- cgit v1.2.3-70-g09d2