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 option for custom FastBoot implementation #751

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,20 @@ fastbootConfigTree() {

The above configuration will be available in Node via the `FastBoot.config()` function. Therefore, in order to get the above config, the addon/app can call `FastBoot.config('<engine-name>')`.

## Custom FastBoot Implementation

This addon comes with the FastBoot library by default. If you must use a specific version of the FastBoot library or a fork of it, you can add it to your `package.json` and specify it inside your app's `ember-cli-build.js`:

```js
const FastBoot = require('my-fastboot-fork');

const app = new EmberApp({
fastboot: {
implementation: FastBoot
}
});
```

## Known Limitations

While FastBoot is under active development, there are several major
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const fs = require('fs');

const MergeTrees = require('broccoli-merge-trees');
const FastBootExpressMiddleware = require('fastboot-express-middleware');
const FastBoot = require('fastboot');
const chalk = require('chalk');

const fastbootAppBoot = require('./lib/utilities/fastboot-app-boot');
Expand Down Expand Up @@ -307,6 +306,9 @@ module.exports = {
},

serverMiddleware(options) {
const { implementation } = this.app.options.fastboot || {};
const FastBoot = implementation || require('fastboot');

let emberCliVersion = this._getEmberCliVersion();
let app = options.app;

Expand Down
41 changes: 41 additions & 0 deletions test/custom-implementation-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'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('custom fastboot implementation', function() {
this.timeout(300000);

let app;

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

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

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

it('uses custom implementation', function() {
return request({
url: 'http://localhost:49741/',
headers: {
'Accept': 'text/html'
}
})
.then(function(response) {
expect(response.statusCode).to.equal(200);
expect(response.body).to.equal('foobar');
});
});
});
1 change: 1 addition & 0 deletions test/fixtures/custom-implementation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This fixture app demonstrates the use of a custom FastBoot implementation.
51 changes: 51 additions & 0 deletions test/fixtures/custom-implementation/config/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* jshint node: true */

module.exports = function(environment) {
var ENV = {
modulePrefix: 'custom-implementation',
environment: environment,
baseURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
}
},

APP: {
// Here you can pass flags/options to your application instance
// when it is created
},

fastboot: {
hostWhitelist: ['example.com', 'subdomain.example.com', /localhost:\d+/]
}
};

if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}

if (environment === 'test') {
// Testem prefers this...
ENV.baseURL = '/';
ENV.locationType = 'none';

// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;

ENV.APP.rootElement = '#ember-testing';
}

if (environment === 'production') {

}

return ENV;
};
30 changes: 30 additions & 0 deletions test/fixtures/custom-implementation/ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class FakeFastBoot {
visit() {
return new Promise(resolve => {
resolve({
statusCode: 200,
headers: {
entries() {
return [];
}
},
html() {
return new Promise(resolve => {
resolve('foobar');
});
}
})
});
}
}

module.exports = function(defaults) {
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var app = new EmberApp(defaults, {
fastboot: {
implementation: FakeFastBoot
}
});

return app.toTree();
};