Skip to content

Commit 365c2ba

Browse files
authored
Merge pull request #371 from kratiahuja/disable-fastboot-serve
Enable a way to disable fastboot serving
2 parents 878965c + d01c3f6 commit 365c2ba

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ ember install ember-cli-fastboot
3333
* `ember fastboot --serve-assets`
3434
* Visit your app at `http://localhost:3000`.
3535

36-
**Note**: If your app is running ember-cli v2.12.0-beta.1+, you can just use `ember serve` instead of `ember fastboot --serve-assets`.
36+
### With `ember-cli` version 2.12.0-beta.1 and above
37+
If your app is running ember-cli v2.12.0-beta.1+, you can just use `ember serve` instead of `ember fastboot --serve-assets` and visit at `http://localhost:4200/`.
38+
39+
Optionally you can even disable the fastboot serving at runtime using the `fastboot` query parameter. Example to turn off fastboot serving,
40+
visit your app at `http://localhost:4200/?fastboot=false`. If you want to turn on fastboot serving again, simply visit at `http://localhost:4200/?fastboot=true` or `http://localhost:4200/`.
41+
42+
You can even disable serving fastboot with `ember serve` using an environment flag: `FASTBOOT_DISABLED=true ember serve`. If you have disabled building fastboot assets using the same flag as described [here](https://github.com/ember-fastboot/ember-cli-fastboot#double-build-times-and-no-incremental-builds), remember to also disable serving fastboot assets when using `ember serve`.
3743

3844
You may be shocked to learn that minified code runs faster in Node than
3945
non-minified code, so you will probably want to run the production
@@ -392,7 +398,7 @@ inside of the sandbox environment. For this reason, it's encouraged to [disable
392398
Due to limitations in Ember CLI, builds take twice as long to generate the
393399
second set of FastBoot assets. This also means incremental builds with
394400
live reload don't work either. This aims to be resolved by FastBoot 1.0.
395-
In the mean time, we introduce a short-circuit evironment flag to not do
401+
In the mean time, we introduce a short-circuit environment flag to not do
396402
a FastBoot build:
397403

398404
```

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ module.exports = {
152152
// that version contains API to hook fastboot into ember-cli
153153

154154
app.use((req, resp, next) => {
155+
var fastbootQueryParam = (req.query.hasOwnProperty('fastboot') && req.query.fastboot === 'false') ? false : true;
156+
var enableFastBootServe = !process.env.FASTBOOT_DISABLED && fastbootQueryParam;
155157
var broccoliHeader = req.headers['x-broccoli'];
156158
var outputPath = broccoliHeader['outputPath'];
157159

158-
if (broccoliHeader['url'] === req.serveUrl) {
160+
if (broccoliHeader['url'] === req.serveUrl && enableFastBootServe) {
159161
// if it is a base page request, then have fastboot serve the base page
160-
// TODO(future): provide a way to turn this off without needing to uninstall this addon
161162
if (!this.fastboot) {
162163
// TODO(future): make this configurable for allowing apps to pass sandboxGlobals
163164
// and custom sandbox class

test/simple-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,34 @@ describe('simple acceptance', function() {
105105
});
106106
});
107107

108+
it('with fastboot query parameter turned on', function() {
109+
return request({
110+
url: 'http://localhost:49741/?fastboot=true',
111+
headers: {
112+
'Accept': 'text/html'
113+
}
114+
})
115+
.then(function(response) {
116+
expect(response.statusCode).to.equal(200);
117+
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
118+
expect(response.body).to.contain("Welcome to Ember.js");
119+
});
120+
});
121+
122+
it('with fastboot query parameter turned off', function() {
123+
return request({
124+
url: 'http://localhost:49741/?fastboot=false',
125+
headers: {
126+
'Accept': 'text/html'
127+
}
128+
})
129+
.then(function(response) {
130+
expect(response.statusCode).to.equal(200);
131+
expect(response.headers["content-type"]).to.eq("text/html; charset=UTF-8");
132+
expect(response.body).to.contain("<!-- EMBER_CLI_FASTBOOT_BODY -->");
133+
});
134+
});
135+
108136
it('/posts HTML contents', function() {
109137
return request({
110138
url: 'http://localhost:49741/posts',

0 commit comments

Comments
 (0)