aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/xtext/fetchBackendConfig.ts
blob: f8087a70f330add33c0bd24e47624123d8cdea4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* eslint-disable @typescript-eslint/no-redeclare -- Declare types with their companion objects */

import { z } from 'zod';

export const BackendConfig = z.object({
  webSocketURL: z.string().url(),
});

export type BackendConfig = z.infer<typeof BackendConfig>;

export default async function fetchBackendConfig(): Promise<BackendConfig> {
  const configURL = `${import.meta.env.BASE_URL}config.json`;
  const response = await fetch(configURL);
  const rawConfig = (await response.json()) as unknown;
  return BackendConfig.parse(rawConfig);
}