Imitate the REST api using url parameter based implementation
Reason for this implementation is some clients having trouble configuring the rest api either due to not having proper access to the webserver in a shared hosting environment or security restrictions. But still from icehrm frontend we need to consume the backend rest api.
This commit is contained in:
@@ -55,7 +55,7 @@ class AdapterBase extends ModuleBase {
|
||||
}
|
||||
|
||||
setupApiClient(token) {
|
||||
this.apiClient = new IceApiClient(this.apiUrl, token);
|
||||
this.apiClient = new IceApiClient(this.apiUrl, token, window.CLIENT_BASE_URL, true);
|
||||
}
|
||||
|
||||
setApiUrl(apiUrl) {
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
const axios = require('axios');
|
||||
|
||||
class IceApiClient {
|
||||
constructor(baseUrl, token) {
|
||||
constructor(baseUrl, token, clientBaseUrl, legacyApiWrapper = true) {
|
||||
this.baseUrl = baseUrl;
|
||||
this.token = token;
|
||||
this.clientBaseUrl = clientBaseUrl;
|
||||
this.legacyApiWrapper = legacyApiWrapper;
|
||||
}
|
||||
|
||||
get(endpoint) {
|
||||
if (this.legacyApiWrapper) {
|
||||
const url = `${this.clientBaseUrl}rest.php?token=${this.token}&method=get&url=/${endpoint}`;
|
||||
return axios.get(url);
|
||||
}
|
||||
|
||||
return axios.get(this.baseUrl + endpoint, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.token}`,
|
||||
|
||||
Reference in New Issue
Block a user