* Add vue-rx, rxjs and lodash as dependencies * Added vue-rx plugin integration to nuxt config * Initial settings store implementation * Add babel plugin for private class properties to for Jest * Add DispatchingStore test spec * Initial settings code * Reactive Streams for fb current user and id token * Fix typo * Migrate index and graphql pages to the new store * Migrate network strategy to the new store * Fixed Section.vue errors * Fix getSettingSubject issue * Migrate fb settings reference in components to the new state system * Add typings for lodash as dev dependency * Load setting * Load initial sync setting values * Update proxy url * Add typescript support * Rewrite Settings store to TypeScript * Port Settings page to TypeScript as reference * Move all store migrations to a separate file * Delete test file for fb.js * Add ts-jest as dev dependency * Remove firebase-mock as dependency * Remove FRAME_COLORS_ENABLED settings value
76 lines
1.5 KiB
JavaScript
76 lines
1.5 KiB
JavaScript
import axios from "axios"
|
|
import { decodeB64StringToArrayBuffer } from "../utils/b64"
|
|
import { settingsStore } from "~/newstore/settings"
|
|
|
|
let cancelSource = axios.CancelToken.source()
|
|
|
|
export const cancelRunningAxiosRequest = () => {
|
|
cancelSource.cancel()
|
|
|
|
// Create a new cancel token
|
|
cancelSource = axios.CancelToken.source()
|
|
}
|
|
|
|
const axiosWithProxy = async (req) => {
|
|
try {
|
|
const { data } = await axios.post(
|
|
settingsStore.value.PROXY_URL || "https://proxy.hoppscotch.io",
|
|
{
|
|
...req,
|
|
wantsBinary: true,
|
|
},
|
|
{
|
|
cancelToken: cancelSource.token,
|
|
}
|
|
)
|
|
|
|
if (!data.success) {
|
|
throw new Error(data.data.message || "Proxy Error")
|
|
}
|
|
|
|
if (data.isBinary) {
|
|
data.data = decodeB64StringToArrayBuffer(data.data)
|
|
}
|
|
|
|
return data
|
|
} catch (e) {
|
|
// Check if the throw is due to a cancellation
|
|
if (axios.isCancel(e)) {
|
|
throw "cancellation"
|
|
} else {
|
|
throw e
|
|
}
|
|
}
|
|
}
|
|
|
|
const axiosWithoutProxy = async (req, _store) => {
|
|
try {
|
|
const res = await axios({
|
|
...req,
|
|
cancelToken: (cancelSource && cancelSource.token) || "",
|
|
responseType: "arraybuffer",
|
|
})
|
|
|
|
return res
|
|
} catch (e) {
|
|
if (axios.isCancel(e)) {
|
|
throw "cancellation"
|
|
} else {
|
|
throw e
|
|
}
|
|
}
|
|
}
|
|
|
|
const axiosStrategy = (req) => {
|
|
if (settingsStore.value.PROXY_ENABLED) {
|
|
return axiosWithProxy(req)
|
|
}
|
|
return axiosWithoutProxy(req)
|
|
}
|
|
|
|
export const testables = {
|
|
cancelSource,
|
|
}
|
|
|
|
export default axiosStrategy
|