Skip to content

Commit

Permalink
Merge pull request #121 from jelhan/issue-116-inject-runtime-config-o…
Browse files Browse the repository at this point in the history
…nly-if-app-has-fastboot-dependency

inject runtime config only if FastBoot dependency exists
  • Loading branch information
rwjblue authored Dec 21, 2019
2 parents c6e6462 + 4ab679a commit 6a19a8d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ module.exports = {
// - application has ember-cli-fastboot dependency.
this._needsFastBootSupport = this._config.enabled &&
this._config.delivery.includes('header') &&
// TODO: check if application has ember-cli-fastboot-dependency
// https://github.com/rwjblue/ember-cli-content-security-policy/issues/116
true;
new VersionChecker(this.project).for('ember-cli-fastboot').exists();

// Run-time configuration is only needed for FastBoot support.
if (!this._needsFastBootSupport) {
Expand Down Expand Up @@ -291,4 +289,3 @@ module.exports = {
// holds calculated policy string
_policyString: null,
};

51 changes: 51 additions & 0 deletions node-tests/e2e/fastboot-support-app-not-using-fastboot-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const expect = require('chai').expect;
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
const denodeify = require('denodeify');
const request = denodeify(require('request'));

function getRunTimeConfig(html) {
let encodedConfig = html.match(/<meta name="default\/config\/environment" content="(.*)" \/>/)[1];
return JSON.parse(decodeURIComponent(encodedConfig));
}

describe('e2e: fastboot integration if consumer does not use FastBoot', function() {
this.timeout(300000);

let app;

before(async function() {
app = new AddonTestApp();

await app.create('default', {
noFixtures: true,
skipNpm: true,
});

await app.editPackageJSON(pkg => {
delete pkg.devDependencies['ember-cli-fastboot'];
delete pkg.devDependencies['fastboot-app-server'];
});

await app.run('npm', 'install');

await app.startServer();
});

after(async function() {
await app.stopServer();
});

it('does not push run-time configuration into app if app does not use FastBoot', async function() {
let response = await request({
url: 'http://localhost:49741',
headers: {
'Accept': 'text/html'
}
});

expect(response.statusCode).to.equal(200);

let runTimeConfig = getRunTimeConfig(response.body);
expect(runTimeConfig).to.not.include.key('ember-cli-content-security-policy');
});
});

0 comments on commit 6a19a8d

Please sign in to comment.