Skip to content

Commit 12e121c

Browse files
committed
Add support for custom configuration
1 parent 6a5d6c6 commit 12e121c

6 files changed

Lines changed: 89 additions & 6 deletions

File tree

index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ module.exports = {
7979
this._appRegistry = app.registry;
8080
this._name = app.name;
8181

82+
this.options = this._optionsFor(app.env, app.project);
83+
8284
migrateInitializers(this.project);
8385
},
8486

@@ -323,13 +325,14 @@ module.exports = {
323325
if (!this.fastboot) {
324326
const broccoliHeader = req.headers['x-broccoli'];
325327
const outputPath = broccoliHeader['outputPath'];
328+
const fastbootOptions = Object.assign(
329+
{},
330+
this.options,
331+
{ distPath: outputPath }
332+
);
326333

327-
// TODO(future): make this configurable for allowing apps to pass sandboxGlobals
328-
// and custom sandbox class
329334
this.ui.writeLine(chalk.green('App is being served by FastBoot'));
330-
this.fastboot = new FastBoot({
331-
distPath: outputPath
332-
});
335+
this.fastboot = new FastBoot(fastbootOptions);
333336
}
334337

335338
let fastbootMiddleware = FastBootExpressMiddleware({
@@ -373,8 +376,17 @@ module.exports = {
373376

374377
return checker.for('ember', 'bower');
375378
},
376-
379+
377380
_isModuleUnification() {
378381
return (typeof this.project.isModuleUnification === 'function') && this.project.isModuleUnification();
382+
},
383+
384+
_optionsFor(environment, project) {
385+
const configPath = path.join(path.dirname(project.configPath()), 'fastboot.js');
386+
387+
if (fs.existsSync(configPath)) {
388+
return require(configPath)(environment);
389+
}
390+
return {};
379391
}
380392
};

test/fastboot-config-test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const expect = require('chai').use(require('chai-string')).expect;
4+
const RSVP = require('rsvp');
5+
const request = RSVP.denodeify(require('request'));
6+
7+
const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;
8+
9+
describe('FastBoot config', function() {
10+
this.timeout(400000);
11+
12+
let app;
13+
14+
before(function() {
15+
app = new AddonTestApp();
16+
17+
return app.create('fastboot-config')
18+
.then(function() {
19+
return app.startServer({
20+
command: 'serve'
21+
});
22+
});
23+
});
24+
25+
after(function() {
26+
return app.stopServer();
27+
});
28+
29+
it('provides sandbox globals', function() {
30+
return request({
31+
url: 'http://localhost:49741/',
32+
headers: {
33+
'Accept': 'text/html'
34+
}
35+
})
36+
.then(function(response) {
37+
expect(response.statusCode).to.equal(200);
38+
expect(response.headers['content-type']).to.equalIgnoreCase('text/html; charset=utf-8');
39+
expect(response.body).to.contain('<h1>My Global</h1>');
40+
});
41+
});
42+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Ember from 'ember';
2+
import config from './config/environment';
3+
4+
const Router = Ember.Router.extend({
5+
location: config.locationType,
6+
rootURL: config.rootURL
7+
});
8+
9+
Router.map(function() {
10+
});
11+
12+
export default Router;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Ember from 'ember';
2+
3+
export default Ember.Route.extend({
4+
model() {
5+
if (typeof FastBoot !== 'undefined') {
6+
return window.myGlobal;
7+
}
8+
}
9+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>{{this.model}}</h1>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function(environment) {
2+
return {
3+
sandboxGlobals: {
4+
myGlobal: 'My Global'
5+
}
6+
};
7+
}

0 commit comments

Comments
 (0)