diff --git a/Dockerfile b/Dockerfile index dd6fed9fd..0eb17609a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,6 +39,7 @@ EXPOSE 3000 EXPOSE 3001 EXPOSE 3002 EXPOSE 3005 +EXPOSE 9229 WORKDIR /opt/one-app RUN chown node:node /opt/one-app USER $USER diff --git a/__tests__/server/config/env/runTime.spec.js b/__tests__/server/config/env/runTime.spec.js index 818a1eb19..f27c5b139 100644 --- a/__tests__/server/config/env/runTime.spec.js +++ b/__tests__/server/config/env/runTime.spec.js @@ -40,6 +40,7 @@ describe('runTime', () => { 'HOLOCRON_MODULE_MAP_URL', 'HTTP_ONE_APP_DEV_CDN_PORT', 'HTTP_ONE_APP_DEV_PROXY_SERVER_PORT', + 'HTTP_ONE_APP_DEBUG_PORT', 'HOLOCRON_SERVER_MAX_MODULES_RETRY', 'HOLOCRON_SERVER_MAX_SIM_MODULES_FETCH', 'ONE_CLIENT_REPORTING_URL', @@ -247,6 +248,35 @@ describe('runTime', () => { }); }); + describe('HTTP_ONE_APP_DEBUG_PORT', () => { + const debugPort = getEnvVarConfig('HTTP_ONE_APP_DEBUG_PORT'); + + it('normalizes numeric input', () => { + expect(debugPort.normalize('1337')).toEqual(1337); + expect(() => debugPort.normalize('r00t')).toThrowErrorMatchingInlineSnapshot( + '"env var HTTP_ONE_APP_DEBUG_PORT needs to be a valid integer, given \\"r00t\\""' + ); + expect(debugPort.normalize('0002345')).toEqual(2345); + expect(() => debugPort.normalize('0002345a')).toThrow(); + }); + + it('does not normalize if no value is given', () => { + expect(debugPort.normalize()).toEqual(undefined); + }); + + it('has a default value for development', () => { + process.env.NODE_ENV = 'development'; + delete process.env.HTTP_ONE_APP_DEV_CDN_PORT; + expect(debugPort.defaultValue()).toBeDefined(); + expect(debugPort.defaultValue()).toBe(9229); + }); + + it('has no default value for production', () => { + process.env.NODE_ENV = 'production'; + expect(debugPort.defaultValue()).not.toBeDefined(); + }); + }); + describe('HTTP_METRICS_PORT', () => { const httpPort = getEnvVarConfig('HTTP_METRICS_PORT'); diff --git a/src/server/config/env/runTime.js b/src/server/config/env/runTime.js index c98a8859a..703c71a53 100644 --- a/src/server/config/env/runTime.js +++ b/src/server/config/env/runTime.js @@ -129,6 +129,25 @@ const runTime = [ ? 3002 : undefined), }, + { + name: 'HTTP_ONE_APP_DEBUG_PORT', + normalize: (input) => { + if (input) { + const parsed = Number.parseInt(input, 10); + // make sure the parsed value is the same value as input + // input may be a string or a number, we don't want === in this case, just == + if (Number.isNaN(parsed) || parsed != input) { // eslint-disable-line eqeqeq + throw new Error(`env var HTTP_ONE_APP_DEBUG_PORT needs to be a valid integer, given "${input}"`); + } else { + return parsed; + } + } + return undefined; + }, + defaultValue: () => (process.env.NODE_ENV === 'development' + ? 9229 + : undefined), + }, // holocron config, the modules to use { name: 'HOLOCRON_MODULE_MAP_URL',