Environment variables in collections #642

This commit is contained in:
Samir L. Boulema
2020-05-07 20:54:38 +02:00
parent 7e3c775f70
commit 8b961fb8cd
2 changed files with 20 additions and 10 deletions

13
functions/utils/uri.js Normal file
View File

@@ -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;
}

View File

@@ -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.path
this.showRequestModal = true
},
hideRequestModal() {