Skip to content

Commit

Permalink
Sending all of hostConfig. (blackbaud#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobby Earl authored Feb 7, 2020
1 parent b878948 commit 3907f09
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
20 changes: 18 additions & 2 deletions test/utils-host-utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ describe('host-utils', () => {
mock('html-webpack-plugin/lib/chunksorter', {
dependency: (chunks) => chunks
});
utils = require('../utils/host-utils');
utils = mock.reRequire('../utils/host-utils');
});

afterEach(() => {
utils = null;
mock.stop('html-webpack-plugin/lib/chunksorter');
mock.stopAll();
});

it('should resolve a url, trim trailing slash from host and leading slash from url', () => {
Expand Down Expand Up @@ -112,4 +112,20 @@ describe('host-utils', () => {
mock.stop('../package.json');
});

it('should add host config', () => {
const expectedHostConfig = {
url: 'any-url',
frameOptions: {
none: true
}
};

skyPagesConfig.skyux.host = expectedHostConfig;

const resolved = utils.resolve('/url', '', [], skyPagesConfig);
const decoded = decode(resolved);

expect(decoded.host).toEqual(expectedHostConfig);
});

});
15 changes: 9 additions & 6 deletions utils/host-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ const skyPagesConfigUtil = require('../config/sky-pages/sky-pages.config');
* @param {Object} skyPagesConfig
*/
function resolve(url, localUrl, chunks, skyPagesConfig) {
let host = skyPagesConfig.skyux.host.url;
let config = {
const hostConfig = skyPagesConfig.skyux.host;

const config = {
scripts: getScripts(chunks),
localUrl: localUrl
localUrl,
host: hostConfig
};

if (skyPagesConfig.skyux.app && skyPagesConfig.skyux.app.externals) {
Expand All @@ -28,14 +30,15 @@ function resolve(url, localUrl, chunks, skyPagesConfig) {
}

// Trim trailing slash since geAppBase adds it
if (host && host.charAt(host.length - 1) === '/') {
host = host.slice(0, -1);
let hostUrl = hostConfig.url;
if (hostUrl && hostUrl.charAt(hostUrl.length - 1) === '/') {
hostUrl = hostUrl.slice(0, -1);
}

const delimeter = url.indexOf('?') === -1 ? '?' : '&';
const encoded = Buffer.from(JSON.stringify(config)).toString('base64');
const base = skyPagesConfigUtil.getAppBase(skyPagesConfig);
const resolved = `${host}${base}${url}${delimeter}local=true&_cfg=${encoded}`;
const resolved = `${hostUrl}${base}${url}${delimeter}local=true&_cfg=${encoded}`;

return resolved;
}
Expand Down

0 comments on commit 3907f09

Please sign in to comment.