Moved proxy code to be handled in each strategy

This commit is contained in:
Andrew Bastin
2020-01-17 13:27:37 -05:00
parent f7a67ec30f
commit 2a51ec6d9f
3 changed files with 16 additions and 18 deletions

View File

@@ -1,5 +1,4 @@
import AxiosStrategy from "./strategies/AxiosStrategy";
import ProxyStrategy from "./strategies/ProxyStrategy";
import FirefoxStrategy from "./strategies/FirefoxStrategy";
@@ -10,10 +9,6 @@ const runAppropriateStrategy = (req, store) => {
return FirefoxStrategy(req, store);
}
if (store.state.postwoman.settings.PROXY_ENABLED) {
return ProxyStrategy(req, store);
}
return AxiosStrategy(req, store);
}

View File

@@ -1,8 +1,23 @@
import axios from "axios";
const axiosStrategy = async (req, _store) => {
const axiosWithProxy = async (req, store) => {
const { data } = await axios.post(
store.state.postwoman.settings.PROXY_URL ||
"https://postwoman.apollotv.xyz/",
req
);
return data;
}
const axiosWithoutProxy = async (req, _store) => {
const res = await axios(req);
return res;
};
const axiosStrategy = (req, store) => {
if (store.state.postwoman.settings.PROXY_ENABLED)
return axiosWithProxy(req, store);
else return axiosWithoutProxy(req, store);
}
export default axiosStrategy;

View File

@@ -1,12 +0,0 @@
import axios from "axios";
const proxyStrategy = async (req, store) => {
const { data } = await axios.post(
store.state.postwoman.settings.PROXY_URL ||
"https://postwoman.apollotv.xyz/",
req
);
return data;
};
export default proxyStrategy;