Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

feat(*): add one app debug port to runtime and expose #1101

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions __tests__/server/config/env/runTime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');

Expand Down
19 changes: 19 additions & 0 deletions src/server/config/env/runTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading