Merge branch 'master' into feature/post-request-tests

This commit is contained in:
Nicholas Palenchar
2020-01-18 10:51:01 -05:00
30 changed files with 753 additions and 421 deletions

24
functions/network.js Normal file
View File

@@ -0,0 +1,24 @@
import AxiosStrategy from "./strategies/AxiosStrategy";
import ProxyStrategy from "./strategies/ProxyStrategy";
import FirefoxStrategy from "./strategies/FirefoxStrategy";
const runAppropriateStrategy = (req, store) => {
// The firefox plugin injects a function to send requests through it
// If that is available, then we can use the FirefoxStrategy
if (window.firefoxExtSendRequest) {
return FirefoxStrategy(req, store);
}
if (store.state.postwoman.settings.PROXY_ENABLED) {
return ProxyStrategy(req, store);
}
return AxiosStrategy(req, store);
}
const sendNetworkRequest = (req, store) =>
runAppropriateStrategy(req, store)
.finally(() => window.$nuxt.$loading.finish());
export { sendNetworkRequest };

View File

@@ -0,0 +1,8 @@
import axios from "axios";
const axiosStrategy = async (req, _store) => {
const res = await axios(req);
return res;
};
export default axiosStrategy;

View File

@@ -0,0 +1,15 @@
const firefoxStrategy = (req, _store) => new Promise((resolve, reject) => {
const eventListener = (event) => {
window.removeEventListener("firefoxExtSendRequestComplete", eventListener);
if (event.detail.error) reject(JSON.parse(event.detail.error));
else resolve(JSON.parse(event.detail.response));
};
window.addEventListener("firefoxExtSendRequestComplete", eventListener);
window.firefoxExtSendRequest(req);
});
export default firefoxStrategy;

View File

@@ -0,0 +1,12 @@
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;