Skip to content

Commit

Permalink
hack to prevent CORS error
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Jan 13, 2024
1 parent 96a68cd commit 7674189
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ui/src/api/CWaterPumpAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ function preprocessApiHost(apiHost) {

class CWaterPumpAPI {
constructor({ URL }) {
// quick hack to add headers to axios client
// this is needed to prevent CORS error
const axiosClient = axios.create({ baseURL: preprocessApiHost(URL) });
const fakeClient = {
get: async (path, params) => {
params = params || {};
params.headers = params.headers || {};
params.headers['Content-Type'] = 'application/x-www-form-urlencoded';
return await axiosClient.get(path, params);
}
};
this._impl = new CWaterPumpAPIImpl({
client: axios.create({ baseURL: preprocessApiHost(URL) }),
client: fakeClient,
});
}

Expand Down

0 comments on commit 7674189

Please sign in to comment.