diff options
author | 2022-11-10 14:35:24 +0100 | |
---|---|---|
committer | 2022-11-10 14:35:24 +0100 | |
commit | 4971c864a603e0c01f7ad84a23697905d096283b (patch) | |
tree | fc2ed2ced39aa50aa98602ad4bd2a9d877577dcd /subprojects/frontend/src/xtext/fetchBackendConfig.ts | |
parent | refactor: rename CallKind to Polarity (diff) | |
download | refinery-4971c864a603e0c01f7ad84a23697905d096283b.tar.gz refinery-4971c864a603e0c01f7ad84a23697905d096283b.tar.zst refinery-4971c864a603e0c01f7ad84a23697905d096283b.zip |
feat(web): backend URL configuration
To point the frontend to a backend server, update the config.json
file in the website root.
The config.json is generated automatically in debug mode and when
running from a standalone jar.
Diffstat (limited to 'subprojects/frontend/src/xtext/fetchBackendConfig.ts')
-rw-r--r-- | subprojects/frontend/src/xtext/fetchBackendConfig.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/subprojects/frontend/src/xtext/fetchBackendConfig.ts b/subprojects/frontend/src/xtext/fetchBackendConfig.ts new file mode 100644 index 00000000..f8087a70 --- /dev/null +++ b/subprojects/frontend/src/xtext/fetchBackendConfig.ts | |||
@@ -0,0 +1,16 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-redeclare -- Declare types with their companion objects */ | ||
2 | |||
3 | import { z } from 'zod'; | ||
4 | |||
5 | export const BackendConfig = z.object({ | ||
6 | webSocketURL: z.string().url(), | ||
7 | }); | ||
8 | |||
9 | export type BackendConfig = z.infer<typeof BackendConfig>; | ||
10 | |||
11 | export default async function fetchBackendConfig(): Promise<BackendConfig> { | ||
12 | const configURL = `${import.meta.env.BASE_URL}config.json`; | ||
13 | const response = await fetch(configURL); | ||
14 | const rawConfig = (await response.json()) as unknown; | ||
15 | return BackendConfig.parse(rawConfig); | ||
16 | } | ||