Load server config on react app
This commit is contained in:
47
geneit_app/src/api/ServerApi.ts
Normal file
47
geneit_app/src/api/ServerApi.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { APIClient } from "./ApiClient";
|
||||
|
||||
interface LenConstraint {
|
||||
min: number;
|
||||
max: number;
|
||||
}
|
||||
|
||||
interface Constraints {
|
||||
mail_len: LenConstraint;
|
||||
user_name_len: LenConstraint;
|
||||
password_len: LenConstraint;
|
||||
}
|
||||
|
||||
interface OIDCProvider {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface ServerConfig {
|
||||
constraints: Constraints;
|
||||
mail: string;
|
||||
oidc_providers: OIDCProvider[];
|
||||
}
|
||||
|
||||
let config: ServerConfig | null = null;
|
||||
|
||||
export class ServerApi {
|
||||
/**
|
||||
* Get server configuration
|
||||
*/
|
||||
static async LoadConfig(): Promise<void> {
|
||||
config = (
|
||||
await APIClient.exec({
|
||||
uri: "/server/config",
|
||||
method: "GET",
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached configuration
|
||||
*/
|
||||
static Config(): ServerConfig {
|
||||
if (config === null) throw new Error("Missing configuration!");
|
||||
return config;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user