Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
Environment variables in collections #642
Samir L. Boulema8b961fb8cdd8
diff --git a/functions/utils/uri.js b/functions/utils/uri.jsnew file mode 100644index 000000000..3fd4091de--- /dev/null+++ b/functions/utils/uri.js@@ -0,0 +1,13 @@+export function parseUrlAndPath(value) {+ let result = {}+ try {+ let url = new URL(value)+ result.url = url.origin+ result.path = url.pathname+ } catch (error) {+ let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/)+ result.url = uriRegex[1]+ result.path = uriRegex[4]+ }+ return result;+}\ No newline at end of filediff --git a/pages/index.vue b/pages/index.vueindex 3bbc271b2..91133edd5 100644--- a/pages/index.vue+++ b/pages/index.vue@@ -1330,6 +1330,7 @@ import { sendNetworkRequest } from "../functions/network"import { fb } from "../functions/fb"import { getEditorLangForMimeType } from "~/functions/editorutils"import { hasPathParams, addPathParamsToVariables, getQueryParams } from "../functions/requestParams.js"+import { parseUrlAndPath } from "../functions/utils/uri.js"const statusCategories = [{name: "informational",@@ -1603,16 +1604,9 @@ export default {environmentVariables = addPathParamsToVariables(this.params, environmentVariables)url = parseTemplateString(value, environmentVariables)}- try {- url = new URL(url)- this.url = url.origin- this.path = url.pathname- } catch (error) {- console.log(error)- let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/)- this.url = uriRegex[1]- this.path = uriRegex[4]- }+ let result = parseUrlAndPath(url)+ this.url = result.url+ this.path = result.path},},url: {@@ -2633,6 +2627,9 @@ export default {if (this.selectedRequest.url) {this.editRequest = Object.assign({}, this.selectedRequest, this.editRequest)}+ let result = parseUrlAndPath(this.uri)+ this.url = result.url+ this.path = result.paththis.showRequestModal = true},hideRequestModal() {