diff --git a/packages/hoppscotch-app/components/smart/EnvInput.vue b/packages/hoppscotch-app/components/smart/EnvInput.vue index 3fd0d251f..8d8dcb31b 100644 --- a/packages/hoppscotch-app/components/smart/EnvInput.vue +++ b/packages/hoppscotch-app/components/smart/EnvInput.vue @@ -41,6 +41,7 @@ import { HoppReactiveEnvPlugin } from "~/helpers/editor/extensions/HoppEnvironme import { useReadonlyStream } from "~/helpers/utils/composables" import { AggregateEnvironment, aggregateEnvs$ } from "~/newstore/environments" import { HoppReactiveVarPlugin } from "~/helpers/editor/extensions/HoppVariable" +import { restVars$ } from "~/newstore/RESTSession" const props = withDefaults( defineProps<{ @@ -114,6 +115,8 @@ const aggregateEnvs = useReadonlyStream(aggregateEnvs$, []) as Ref< AggregateEnvironment[] > +const aggregateVars = useReadonlyStream(restVars$, []) as Ref + const envVars = computed(() => props.envs ? props.envs.map((x) => ({ @@ -130,7 +133,7 @@ const varVars = computed(() => key: x.key, value: x.value, })) - : ([{ key: "size", value: "500" }] as HoppRESTVar[]) + : aggregateVars.value ) const envTooltipPlugin = new HoppReactiveEnvPlugin(envVars, view) diff --git a/packages/hoppscotch-app/helpers/RequestRunner.ts b/packages/hoppscotch-app/helpers/RequestRunner.ts index a6e38ce81..9d8722424 100644 --- a/packages/hoppscotch-app/helpers/RequestRunner.ts +++ b/packages/hoppscotch-app/helpers/RequestRunner.ts @@ -77,6 +77,7 @@ export const runRESTRequest$ = (): TaskEither< name: "Env", variables: combineEnvVariables(envs), }) + console.log("effectiveRequest", effectiveRequest) const stream = createRESTNetworkRequestStream(effectiveRequest) diff --git a/packages/hoppscotch-app/helpers/utils/EffectiveURL.ts b/packages/hoppscotch-app/helpers/utils/EffectiveURL.ts index fae74280e..fbdad1a6b 100644 --- a/packages/hoppscotch-app/helpers/utils/EffectiveURL.ts +++ b/packages/hoppscotch-app/helpers/utils/EffectiveURL.ts @@ -29,6 +29,7 @@ export interface EffectiveHoppRESTRequest extends HoppRESTRequest { effectiveFinalHeaders: { key: string; value: string }[] effectiveFinalParams: { key: string; value: string }[] effectiveFinalBody: FormData | string | null + effectiveFinalVars: { key: string; value: string }[] } /** @@ -299,14 +300,21 @@ export function getEffectiveRESTRequest( })) ) + const effectiveFinalVars = request.vars + const effectiveFinalBody = getFinalBodyFromRequest(request, envVariables) return { ...request, - effectiveFinalURL: parseTemplateString(request.endpoint, envVariables), + effectiveFinalURL: parseTemplateString( + request.endpoint, + envVariables, + request.vars + ), effectiveFinalHeaders, effectiveFinalParams, effectiveFinalBody, + effectiveFinalVars, } } diff --git a/packages/hoppscotch-data/src/environment.ts b/packages/hoppscotch-data/src/environment.ts index 415977344..6fad88619 100644 --- a/packages/hoppscotch-data/src/environment.ts +++ b/packages/hoppscotch-data/src/environment.ts @@ -9,7 +9,13 @@ export type Environment = { }[] } +export type Variables = { + key: string + value: string +}[] + const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<>" +const REGEX_PATH_VAR = /{{([^>]*)}}/g // "{{myVariable}}" /** * How much times can we expand environment variables