Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom configuration #752

Merged
merged 3 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 18 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ module.exports = {
this._appRegistry = app.registry;
this._name = app.name;

this.options = this._optionsFor(app.env, app.project);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Maybe better to name this this.fastbootOptions for clarity.


migrateInitializers(this.project);
},

Expand Down Expand Up @@ -323,13 +325,14 @@ module.exports = {
if (!this.fastboot) {
const broccoliHeader = req.headers['x-broccoli'];
const outputPath = broccoliHeader['outputPath'];
const fastbootOptions = Object.assign(
{},
this.options,
{ distPath: outputPath }
);

// TODO(future): make this configurable for allowing apps to pass sandboxGlobals
// and custom sandbox class
this.ui.writeLine(chalk.green('App is being served by FastBoot'));
this.fastboot = new FastBoot({
distPath: outputPath
});
this.fastboot = new FastBoot(fastbootOptions);
}

let fastbootMiddleware = FastBootExpressMiddleware({
Expand Down Expand Up @@ -373,8 +376,17 @@ module.exports = {

return checker.for('ember', 'bower');
},

_isModuleUnification() {
return (typeof this.project.isModuleUnification === 'function') && this.project.isModuleUnification();
},

_optionsFor(environment, project) {
const configPath = path.join(path.dirname(project.configPath()), 'fastboot.js');

if (fs.existsSync(configPath)) {
return require(configPath)(environment);
}
return {};
kratiahuja marked this conversation as resolved.
Show resolved Hide resolved
}
};
42 changes: 42 additions & 0 deletions test/fastboot-config-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

const expect = require('chai').use(require('chai-string')).expect;
const RSVP = require('rsvp');
const request = RSVP.denodeify(require('request'));

const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;

describe('FastBoot config', function() {
this.timeout(400000);
kratiahuja marked this conversation as resolved.
Show resolved Hide resolved

let app;

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

return app.create('fastboot-config')
.then(function() {
return app.startServer({
command: 'serve'
});
});
});

after(function() {
return app.stopServer();
});

it('provides sandbox globals', function() {
return request({
url: 'http://localhost:49741/',
headers: {
'Accept': 'text/html'
}
})
.then(function(response) {
expect(response.statusCode).to.equal(200);
expect(response.headers['content-type']).to.equalIgnoreCase('text/html; charset=utf-8');
expect(response.body).to.contain('<h1>My Global</h1>');
});
});
});
12 changes: 12 additions & 0 deletions test/fixtures/fastboot-config/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
});

export default Router;
9 changes: 9 additions & 0 deletions test/fixtures/fastboot-config/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Ember from 'ember';

export default Ember.Route.extend({
model() {
if (typeof FastBoot !== 'undefined') {
return window.myGlobal;
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>{{this.model}}</h1>
7 changes: 7 additions & 0 deletions test/fixtures/fastboot-config/config/fastboot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function(environment) {
return {
sandboxGlobals: {
myGlobal: 'My Global'
}
};
}