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

Commit

Permalink
fix(stateConfig): fix path naming
Browse files Browse the repository at this point in the history
  • Loading branch information
enuchi authored and Elisha Nuchi committed Mar 4, 2020
1 parent 7632bec commit c110a7b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions __tests__/server/utils/stateConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/server/utils/stateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
});
}
Expand Down

0 comments on commit c110a7b

Please sign in to comment.