mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-26 06:51:54 +02:00
fix: environment var interpolation issues
This commit is contained in:
parent
1136f1b105
commit
3bf3d30ce8
@ -40,6 +40,7 @@
|
|||||||
"react-hot-toast": "^2.4.0",
|
"react-hot-toast": "^2.4.0",
|
||||||
"react-redux": "^7.2.6",
|
"react-redux": "^7.2.6",
|
||||||
"react-tabs": "^3.2.3",
|
"react-tabs": "^3.2.3",
|
||||||
|
"reckonjs": "^0.1.2",
|
||||||
"sass": "^1.46.0",
|
"sass": "^1.46.0",
|
||||||
"split-on-first": "^3.0.0",
|
"split-on-first": "^3.0.0",
|
||||||
"styled-components": "^5.3.3",
|
"styled-components": "^5.3.3",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import template from 'lodash/template';
|
import reckon from 'reckonjs';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
import each from 'lodash/each';
|
import each from 'lodash/each';
|
||||||
import find from 'lodash/find';
|
import find from 'lodash/find';
|
||||||
@ -356,21 +356,26 @@ export const isLocalCollection = (collection) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const interpolateEnvironmentVars = (item, variables) => {
|
export const interpolateEnvironmentVars = (item, variables) => {
|
||||||
const envVars = {};
|
const envVars = {
|
||||||
const { request } = item;
|
interpolation: { escapeValue: true }
|
||||||
|
};
|
||||||
|
const _item = item.draft ? item.draft : item;
|
||||||
|
const { request } = _item;
|
||||||
each(variables, (variable) => {
|
each(variables, (variable) => {
|
||||||
envVars[variable.name] = variable.value;
|
envVars[variable.name] = variable.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
const templateOpts = {
|
// TODO: Find a better interpolation library
|
||||||
interpolate: /{{([\s\S]+?)}}/g, //interpolate content using markers `{{}}`
|
const interpolate = (str) => {
|
||||||
evaluate: null, // prevent any js evaluation
|
if(!str || !str.length || typeof str !== "string") {
|
||||||
escape: null // disable any escaping
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str.reckon(envVars);
|
||||||
};
|
};
|
||||||
|
|
||||||
const interpolate = (str) => template(str, templateOpts)(envVars);
|
|
||||||
|
|
||||||
request.url = interpolate(request.url);
|
request.url = interpolate(request.url);
|
||||||
|
console.log(request.url);
|
||||||
|
|
||||||
each(request.headers, (header) => {
|
each(request.headers, (header) => {
|
||||||
header.value = interpolate(header.value);
|
header.value = interpolate(header.value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user