mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
ConfigAPI: new class to handle frontend requests to config backend
This new API is somewhat patterned after the InstallAPI, but simpler whenever possible.
This commit is contained in:
parent
960f023618
commit
62a04e9510
31
app/common/ConfigAPI.ts
Normal file
31
app/common/ConfigAPI.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import {BaseAPI, IOptions} from "app/common/BaseAPI";
|
||||||
|
import {addCurrentOrgToPath} from 'app/common/urlUtils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An API for accessing the internal Grist configuration, stored in
|
||||||
|
* config.json.
|
||||||
|
*/
|
||||||
|
export class ConfigAPI extends BaseAPI {
|
||||||
|
constructor(private _homeUrl: string, options: IOptions = {}) {
|
||||||
|
super(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getValue(key: string): Promise<any> {
|
||||||
|
return (await this.requestJson(`${this._url}/api/config/${key}`, {method: 'GET'})).value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async setValue(value: any, restart=false): Promise<void> {
|
||||||
|
await this.request(`${this._url}/api/config`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
body: JSON.stringify({config: value, restart}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async restartServer(): Promise<void> {
|
||||||
|
await this.request(`${this._url}/api/admin/restart`, {method: 'POST'});
|
||||||
|
}
|
||||||
|
|
||||||
|
private get _url(): string {
|
||||||
|
return addCurrentOrgToPath(this._homeUrl);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user