Skip to content

Commit da526fb

Browse files
committed
Support storeConfigInMeta, add config to package.json
Fixes #160 * Stop forcing `storeConfigInMeta` to false in the browser build * Store the application config in `package.json` * Bump `ember-fastboot-server` version to 0.7.3
1 parent cae445f commit da526fb

5 files changed

Lines changed: 40 additions & 15 deletions

File tree

index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ module.exports = {
3535
*/
3636
included: function(app) {
3737
patchEmberApp(app);
38+
},
3839

39-
// We serve the index.html from fastboot-dist, so this has to apply to both builds
40-
app.options.storeConfigInMeta = false;
40+
config: function() {
41+
if (this.app && this.app.options.__is_building_fastboot__) {
42+
return { APP: { autoboot: false } };
43+
}
4144
},
4245

4346
/**
4447
* Inserts placeholders into index.html that are used by the FastBoot server
4548
* to insert the rendered content into the right spot. Also injects a module
4649
* for FastBoot application boot.
4750
*/
48-
contentFor: function(type, config) {
51+
contentFor: function(type, config, contents) {
4952
if (type === 'body') {
5053
return "<!-- EMBER_CLI_FASTBOOT_BODY -->";
5154
}
@@ -57,6 +60,17 @@ module.exports = {
5760
if (type === 'app-boot') {
5861
return fastbootAppModule(config.modulePrefix);
5962
}
63+
64+
if (type === 'config-module' && this.app.options.__is_building_fastboot__) {
65+
var linesToRemove = contents.length;
66+
while(linesToRemove) {
67+
// Clear out the default config from ember-cli
68+
contents.pop();
69+
linesToRemove--;
70+
}
71+
72+
return 'return FastBoot.config();';
73+
}
6074
},
6175

6276
/**

lib/broccoli/fastboot-build.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ FastBootBuild.prototype.appOptions = function() {
106106
FastBootBuild.prototype.buildConfigTree = function(tree) {
107107
var FastBootConfig = require('./fastboot-config');
108108
var env = this.app.env;
109+
var config = this.project.config(env);
110+
var fastbootConfig = config.fastboot;
109111

110112
// Create a new Broccoli tree that writes the FastBoot app's
111113
// `package.json`.
@@ -115,7 +117,8 @@ FastBootBuild.prototype.buildConfigTree = function(tree) {
115117
assetMapPath: this.assetMapPath,
116118
outputPaths: this.app.options.outputPaths,
117119
ui: this.ui,
118-
fastbootAppConfig: this.project.config(env).fastboot
120+
fastbootAppConfig: fastbootConfig,
121+
appConfig: config
119122
});
120123
};
121124

@@ -131,16 +134,8 @@ FastBootBuild.prototype.buildFastBootProject = function() {
131134
var Project = require('ember-cli/lib/models/project');
132135
var oldProject = this.project;
133136
var project = new Project(oldProject.root, oldProject.pkg, oldProject.ui, oldProject.cli);
134-
project.config = function config() {
135-
var config = Object.getPrototypeOf(this).config.apply(this, arguments);
136137

137-
config.APP = config.APP || {};
138-
config.APP.autoboot = false;
139-
140-
return config;
141-
};
142-
143-
return project;
138+
return this.project = project;
144139
};
145140

146141
module.exports = FastBootBuild;

lib/broccoli/fastboot-config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function FastBootConfig(inputNode, options) {
1414
this.ui = options.ui;
1515
this.fastbootAppConfig = options.fastbootAppConfig;
1616
this.outputPaths = options.outputPaths;
17+
this.appConfig = options.appConfig;
1718
}
1819

1920
FastBootConfig.prototype = Object.create(Plugin.prototype);
@@ -135,7 +136,8 @@ FastBootConfig.prototype.toJSONString = function() {
135136
fastboot: {
136137
moduleWhitelist: this.moduleWhitelist,
137138
manifest: this.manifest,
138-
hostWhitelist: this.normalizeHostWhitelist()
139+
hostWhitelist: this.normalizeHostWhitelist(),
140+
appConfig: this.appConfig
139141
}
140142
}, null, 2);
141143
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"broccoli-merge-trees": "^1.1.1",
6363
"broccoli-plugin": "^1.2.1",
6464
"broccoli-stew": "^1.2.0",
65-
"ember-fastboot-server": "^0.7.2",
65+
"ember-fastboot-server": "^0.7.3",
6666
"express": "^4.8.5",
6767
"fastboot-filter-initializers": "0.0.2",
6868
"lodash.clonedeep": "^4.3.1",

tests/acceptance/package-json-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ describe('generating package.json', function() {
7474
]);
7575
});
7676

77+
it("contains the application config", function() {
78+
var pkg = fs.readJsonSync(app.filePath('dist/package.json'));
79+
80+
expect(pkg.fastboot.appConfig).to.deep.equal({
81+
modulePrefix: 'module-whitelist',
82+
environment: 'development',
83+
baseURL: '/',
84+
locationType: 'auto',
85+
EmberENV: { FEATURES: {} },
86+
APP: { name: 'module-whitelist', version: '0.0.0+', autoboot: false },
87+
fastboot: { hostWhitelist: [ 'example.com', 'subdomain.example.com', {} ] },
88+
exportApplicationGlobal: true
89+
});
90+
});
7791
});
7892

7993
describe('with production FastBoot builds', function() {

0 commit comments

Comments
 (0)