feat: updated the hard coded proxy url with the server fetched (#4773)

This commit is contained in:
Nivedin 2025-02-20 21:16:48 +05:30 committed by GitHub
parent c802056d44
commit da2597d4db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 58 additions and 7 deletions

View file

@ -823,7 +823,7 @@
"proxy_url": "Proxy URL",
"proxy_use_toggle": "Use the proxy middleware to send requests",
"read_the": "Read the",
"reset_default": "Reset to default",
"reset_default": "Use Default Proxy",
"short_codes": "Short codes",
"short_codes_description": "Short codes which were created by you.",
"sidebar_on_left": "Sidebar on left",

View file

@ -36,10 +36,13 @@ import { useSetting } from "~/composables/settings"
import IconRotateCCW from "~icons/lucide/rotate-ccw"
import IconCheck from "~icons/lucide/check"
import { useToast } from "~/composables/toast"
import { computed } from "vue"
import { computed, watch } from "vue"
import { useService } from "dioc/vue"
import { InterceptorService } from "~/services/interceptor.service"
import { proxyInterceptor } from "~/platform/std/interceptors/proxy"
import { useReadonlyStream } from "~/composables/stream"
import { platform } from "~/platform"
import { getDefaultProxyUrl } from "~/helpers/proxyUrl"
const t = useI18n()
const toast = useToast()
@ -48,6 +51,17 @@ const interceptorService = useService(InterceptorService)
const PROXY_URL = useSetting("PROXY_URL")
const currentUser = useReadonlyStream(
platform.auth.getCurrentUserStream(),
platform.auth.getCurrentUser()
)
watch(currentUser, async () => {
if (!currentUser.value) {
PROXY_URL.value = await getDefaultProxyUrl()
}
})
const proxyEnabled = computed(
() =>
interceptorService.currentInterceptorID.value ===
@ -59,8 +73,8 @@ const clearIcon = refAutoReset<typeof IconRotateCCW | typeof IconCheck>(
1000
)
const resetProxy = () => {
PROXY_URL.value = "https://proxy.hoppscotch.io/"
const resetProxy = async () => {
PROXY_URL.value = await getDefaultProxyUrl()
clearIcon.value = IconCheck
toast.success(`${t("state.cleared")}`)
}

View file

@ -0,0 +1,22 @@
import { platform } from "~/platform"
import * as E from "fp-ts/Either"
// Default proxy URL
export const DEFAULT_HOPP_PROXY_URL = "https://proxy.hoppscotch.io/"
// Get default proxy URL from platform or return default
export const getDefaultProxyUrl = async () => {
const proxyAppUrl = platform?.infra?.getProxyAppUrl
if (proxyAppUrl) {
const res = await proxyAppUrl()
if (E.isRight(res)) {
return res.right.value
}
return DEFAULT_HOPP_PROXY_URL
}
return DEFAULT_HOPP_PROXY_URL
}

View file

@ -6,6 +6,7 @@ import { cloneDeep } from "lodash-es"
import { NetworkResponse, NetworkStrategy } from "../network"
import { decodeB64StringToArrayBuffer } from "../utils/b64"
import { settingsStore } from "~/newstore/settings"
import { getDefaultProxyUrl } from "../proxyUrl"
let cancelSource = axios.CancelToken.source()
@ -42,6 +43,8 @@ const getProxyPayload = (
return payload
}
const defaultProxyURL = await getDefaultProxyUrl()
const preProcessRequest = (req: AxiosRequestConfig): AxiosRequestConfig => {
const reqClone = cloneDeep(req)
@ -103,7 +106,7 @@ const axiosWithProxy: NetworkStrategy = (req) =>
TE.tryCatch(
() =>
axios.post(
settingsStore.value.PROXY_URL || "https://proxy.hoppscotch.io",
settingsStore.value.PROXY_URL || defaultProxyURL,
payload,
{
headers,

View file

@ -3,6 +3,7 @@ import { Observable } from "rxjs"
import { distinctUntilChanged, pluck } from "rxjs/operators"
import type { KeysMatching } from "~/types/ts-utils"
import DispatchingStore, { defineDispatchers } from "./DispatchingStore"
import { getDefaultProxyUrl } from "~/helpers/proxyUrl"
export const HoppBgColors = ["system", "light", "dark", "black"] as const
@ -82,6 +83,8 @@ export type SettingsDef = {
CUSTOM_NAMING_STYLE: string
}
const defaultProxyURL = await getDefaultProxyUrl()
export const getDefaultSettings = (): SettingsDef => ({
syncCollections: true,
syncHistory: true,
@ -111,7 +114,7 @@ export const getDefaultSettings = (): SettingsDef => ({
CURRENT_INTERCEPTOR_ID: "",
// TODO: Interceptor related settings should move under the interceptor systems
PROXY_URL: "https://proxy.hoppscotch.io/",
PROXY_URL: defaultProxyURL,
URL_EXCLUDES: {
auth: true,
httpUser: true,

View file

@ -1,5 +1,11 @@
import * as E from "fp-ts/Either"
type ProxyAppUrl = {
value: string
name: string
}
export type InfraPlatformDef = {
getIsSMTPEnabled?: () => Promise<E.Either<string, boolean>>
getProxyAppUrl?: () => Promise<E.Either<string, ProxyAppUrl>>
}

View file

@ -7,6 +7,7 @@ import axios from "axios"
import { settingsStore } from "~/newstore/settings"
import { decodeB64StringToArrayBuffer } from "~/helpers/utils/b64"
import SettingsProxy from "~/components/settings/Proxy.vue"
import { getDefaultProxyUrl } from "~/helpers/proxyUrl"
type ProxyHeaders = {
"multipart-part-key"?: string
@ -36,6 +37,8 @@ const getProxyPayload = (
return payload
}
const defaultProxyURL = await getDefaultProxyUrl()
async function runRequest(
req: AxiosRequestConfig,
cancelToken: CancelToken
@ -55,7 +58,7 @@ async function runRequest(
try {
// TODO: Validation for the proxy result
const { data } = await axios.post(
settingsStore.value.PROXY_URL ?? "https://proxy.hoppscotch.io",
settingsStore.value.PROXY_URL ?? defaultProxyURL,
payload,
{
headers,