blob: 7a6bc3dbb947275bf732b55f471ba3d616a5a80e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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';
|