diff --git a/__tests__/server/utils/stateConfig.spec.js b/__tests__/server/utils/stateConfig.spec.js index 0e347497..9fe2a7d2 100644 --- a/__tests__/server/utils/stateConfig.spec.js +++ b/__tests__/server/utils/stateConfig.spec.js @@ -195,6 +195,22 @@ describe('stateConfig methods', () => { expect(getClientStateConfig()).toMatchSnapshot(); expect(getServerStateConfig()).toMatchSnapshot(); }); + it('dev endpoint should not have doubled slash in path', () => { + process.env.NODE_ENV = 'development'; + // eslint-disable-next-line unicorn/import-index, import/no-unresolved + require('fake/path/.dev/endpoints/index.js').mockImplementation(() => ({ + leadingSlashApiUrl: { + devProxyPath: '/leading-slash-api', + destination: 'https://intranet-origin-dev.example.com/some-other-api/v1', + }, + })); + ({ + setStateConfig, + getClientStateConfig, + getServerStateConfig, + } = require('../../../src/server/utils/stateConfig')); + expect(getClientStateConfig().leadingSlashApiUrl).toEqual('http://127.0.0.1:3002/leading-slash-api'); + }); }); describe('with env vars', () => { it('should parse string undefined as js undefined', () => { diff --git a/src/server/utils/stateConfig.js b/src/server/utils/stateConfig.js index 7f9daa17..a446f7ad 100644 --- a/src/server/utils/stateConfig.js +++ b/src/server/utils/stateConfig.js @@ -17,6 +17,7 @@ import ip from 'ip'; import fs from 'fs'; import path from 'path'; +import url from 'url'; import envVarAllowList from './envVarAllowList'; import snakeCaseToCamelCase from './snakeCaseToCamelCase'; @@ -76,7 +77,12 @@ if (process.env.NODE_ENV === 'development' && fs.existsSync(pathToDevEndpoints)) // eslint-disable-next-line global-require,import/no-dynamic-require const devEndpoints = require(pathToDevEndpoints)(); Object.entries(devEndpoints).forEach(([configName, { devProxyPath }]) => { - const value = `http://${ipAddress}:${SERVICES_PORT}/${devProxyPath}`; + const value = url.format({ + protocol: 'http', + hostname: ipAddress, + port: SERVICES_PORT, + pathname: devProxyPath, + }); stateConfigFromDevEndpoints[configName] = value; }); }