From c784df3a6a3c57b00a4d34282b45399474859940 Mon Sep 17 00:00:00 2001 From: Robin Panneels Date: Thu, 19 Dec 2019 12:56:02 +0100 Subject: [PATCH] Use environment variables in .env-file --- lib/proxy.js | 10 +++++++++- package.json | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/proxy.js b/lib/proxy.js index ca71991..9dd5335 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -1,11 +1,17 @@ // heavily inspired by https://github.com/SAP/connect-openui5/blob/master/lib/proxy.js const url = require("url"); const httpProxy = require("http-proxy"); +const dotenv = require("dotenv"); + +// Call dotenv, so that contents in the file are stored in the environment variables +dotenv.config(); const env = { noProxy: process.env.NO_PROXY || process.env.no_proxy, httpProxy: process.env.HTTP_PROXY || process.env.http_proxy, - httpsProxy: process.env.HTTPS_PROXY || process.env.https_proxy + httpsProxy: process.env.HTTPS_PROXY || process.env.https_proxy, + username: process.env.PROXY_USERNAME || process.env.proxy_username, + password: process.env.PROXY_PASSWORD || process.env.proxy_password }; function getProxyUri(uri) { @@ -61,6 +67,8 @@ function createUri(uriParam, baseUri) { module.exports = function({resources, options}) { let proxyServerParameters = {}; + + proxyServerParameters.auth = env.username + ":" + env.password; if (options.configuration.auth) { proxyServerParameters.auth = options.configuration.auth; } diff --git a/package.json b/package.json index 0203d36..f69e54c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui5-middleware-proxy-basicauth", - "version": "0.0.5", + "version": "0.0.6", "description": "UI5 Middleware Proxy with Basic auth", "author": "Koen Schouten", "license": "Apache-2.0", @@ -9,6 +9,7 @@ "url": "https://github.com/Schoutenk/ui5-middleware-proxy-basicauth" }, "dependencies": { - "http-proxy": "^1.18.0" + "http-proxy": "^1.18.0", + "dotenv": "^8.2.0" } } \ No newline at end of file