@@ -13,6 +13,17 @@ function getStartup (req, res) {
1313 res . send ( startUp ) ;
1414}
1515
16+ /**
17+ * A method that replaces the secret placeholders `**SECRET_ABC**` with the environment variable SECRET_ABC
18+ * @param {string } input - the input string
19+ * @returns {string } the input with real variable content
20+ */
21+ function replaceSecretPlaceholder ( input ) {
22+ return input . replaceAll ( / \* \* ( S E C R E T _ [ ^ * ] + ) \* \* / g, ( match , group ) => {
23+ return process . env [ group ] ;
24+ } ) ;
25+ }
26+
1627/**
1728 * A method that forwards HTTP Get-methods to the internet to avoid CORS-errors.
1829 *
@@ -35,10 +46,10 @@ async function cors (req, res) {
3546 return res . status ( 400 ) . send ( url ) ;
3647 } else {
3748 url = match [ 1 ] ;
38- if ( config . hideConfigSecrets ) {
39- url = url . replaceAll ( / \* \* ( S E C R E T _ [ ^ * ] + ) \* \* / g , ( match , group ) => {
40- return process . env [ group ] ;
41- } ) ;
49+ if ( typeof config !== "undefined" ) {
50+ if ( config . hideConfigSecrets ) {
51+ url = replaceSecretPlaceholder ( url ) ;
52+ }
4253 }
4354
4455 const headersToSend = getHeadersToSend ( req . url ) ;
@@ -191,4 +202,4 @@ function getConfigFilePath () {
191202 return path . resolve ( global . configuration_file || `${ global . root_path } /config/config.js` ) ;
192203}
193204
194- module . exports = { cors, getHtml, getVersion, getStartup, getEnvVars, getEnvVarsAsObj, getUserAgent, getConfigFilePath } ;
205+ module . exports = { cors, getHtml, getVersion, getStartup, getEnvVars, getEnvVarsAsObj, getUserAgent, getConfigFilePath, replaceSecretPlaceholder } ;
0 commit comments