-
Notifications
You must be signed in to change notification settings - Fork 0
/
servers.ts
43 lines (37 loc) · 1.36 KB
/
servers.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
*
* Represents the configuration of a server including its
* url template and variable configuration based on the url.
*
*/
export class ServerConfiguration<T extends { [key: string]: string }> {
public constructor(private url: string, private variableConfiguration: T, private description: string) {}
/**
* Sets the value of the variables of this server.
*
* @param variableConfiguration a partial variable configuration for the variables contained in the url
*/
public setVariables(variableConfiguration: Partial<T>) {
Object.assign(this.variableConfiguration, variableConfiguration);
}
public getConfiguration(): T {
return this.variableConfiguration;
}
public getDescription(): string {
return this.description;
}
/**
* Constructions the URL this server using the url with variables
* replaced with their respective values
*/
public getUrl(): string {
let replacedUrl = this.url;
for (const key in this.variableConfiguration) {
var re = new RegExp("{" + key + "}","g");
replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]);
}
return replacedUrl;
}
}
const server1 = new ServerConfiguration<{ }>("https://api.authlete.com", { }, "Shared production server.");
export const servers = [server1];