From 38bc2c12c38f30d2dcb99bfb06015f0d9250ef11 Mon Sep 17 00:00:00 2001 From: Nivedin <53208152+nivedin@users.noreply.github.com> Date: Fri, 10 May 2024 14:01:43 +0530 Subject: [PATCH] refactor: set default interceptor to "proxy" (#4051) --- .../src/newstore/settings.ts | 101 ++++++++++-------- packages/hoppscotch-selfhost-web/src/main.ts | 2 +- 2 files changed, 58 insertions(+), 45 deletions(-) diff --git a/packages/hoppscotch-common/src/newstore/settings.ts b/packages/hoppscotch-common/src/newstore/settings.ts index fe86430f7..778de8d47 100644 --- a/packages/hoppscotch-common/src/newstore/settings.ts +++ b/packages/hoppscotch-common/src/newstore/settings.ts @@ -1,9 +1,10 @@ -import { pluck, distinctUntilChanged } from "rxjs/operators" import { cloneDeep, defaultsDeep, has } from "lodash-es" import { Observable } from "rxjs" - -import DispatchingStore, { defineDispatchers } from "./DispatchingStore" +import { distinctUntilChanged, pluck } from "rxjs/operators" +import { nextTick } from "vue" +import { platform } from "~/platform" import type { KeysMatching } from "~/types/ts-utils" +import DispatchingStore, { defineDispatchers } from "./DispatchingStore" export const HoppBgColors = ["system", "light", "dark", "black"] as const @@ -69,51 +70,63 @@ export type SettingsDef = { HAS_OPENED_SPOTLIGHT: boolean } -export const getDefaultSettings = (): SettingsDef => ({ - syncCollections: true, - syncHistory: true, - syncEnvironments: true, +export const getDefaultSettings = (): SettingsDef => { + const defaultSettings: SettingsDef = { + syncCollections: true, + syncHistory: true, + syncEnvironments: true, - WRAP_LINES: { - httpRequestBody: true, - httpResponseBody: true, - httpHeaders: true, - httpParams: true, - httpUrlEncoded: true, - httpPreRequest: true, - httpTest: true, - httpRequestVariables: true, - graphqlQuery: true, - graphqlResponseBody: true, - graphqlHeaders: false, - graphqlVariables: false, - graphqlSchema: true, - importCurl: true, - codeGen: true, - cookie: true, - }, + WRAP_LINES: { + httpRequestBody: true, + httpResponseBody: true, + httpHeaders: true, + httpParams: true, + httpUrlEncoded: true, + httpPreRequest: true, + httpTest: true, + httpRequestVariables: true, + graphqlQuery: true, + graphqlResponseBody: true, + graphqlHeaders: false, + graphqlVariables: false, + graphqlSchema: true, + importCurl: true, + codeGen: true, + cookie: true, + }, - CURRENT_INTERCEPTOR_ID: "browser", // TODO: Allow the platform definition to take this place + CURRENT_INTERCEPTOR_ID: "", - // TODO: Interceptor related settings should move under the interceptor systems - PROXY_URL: "https://proxy.hoppscotch.io/", - URL_EXCLUDES: { - auth: true, - httpUser: true, - httpPassword: true, - bearerToken: true, - oauth2Token: true, - }, - THEME_COLOR: "indigo", - BG_COLOR: "system", - TELEMETRY_ENABLED: true, - EXPAND_NAVIGATION: false, - SIDEBAR: true, - SIDEBAR_ON_LEFT: false, - COLUMN_LAYOUT: true, + // TODO: Interceptor related settings should move under the interceptor systems + PROXY_URL: "https://proxy.hoppscotch.io/", + URL_EXCLUDES: { + auth: true, + httpUser: true, + httpPassword: true, + bearerToken: true, + oauth2Token: true, + }, + THEME_COLOR: "indigo", + BG_COLOR: "system", + TELEMETRY_ENABLED: true, + EXPAND_NAVIGATION: false, + SIDEBAR: true, + SIDEBAR_ON_LEFT: false, + COLUMN_LAYOUT: true, - HAS_OPENED_SPOTLIGHT: false, -}) + HAS_OPENED_SPOTLIGHT: false, + } + + // Wait for platform to initialize before setting CURRENT_INTERCEPTOR_ID + nextTick(() => { + applySetting( + "CURRENT_INTERCEPTOR_ID", + platform?.interceptors.default || "browser" + ) + }) + + return defaultSettings +} type ApplySettingPayload = { [K in keyof SettingsDef]: { diff --git a/packages/hoppscotch-selfhost-web/src/main.ts b/packages/hoppscotch-selfhost-web/src/main.ts index c54447ccf..604481418 100644 --- a/packages/hoppscotch-selfhost-web/src/main.ts +++ b/packages/hoppscotch-selfhost-web/src/main.ts @@ -26,7 +26,7 @@ createHoppApp("#app", { history: historyDef, }, interceptors: { - default: "browser", + default: "proxy", interceptors: [ { type: "standalone", interceptor: browserInterceptor }, { type: "standalone", interceptor: proxyInterceptor },