Skip to content

Instantly share code, notes, and snippets.

@jasonmit
Last active July 13, 2016 00:21
Show Gist options
  • Select an option

  • Save jasonmit/2460b43c445273e26b91d35b04ef9ffa to your computer and use it in GitHub Desktop.

Select an option

Save jasonmit/2460b43c445273e26b91d35b04ef9ffa to your computer and use it in GitHub Desktop.
import Fastboot from 'fastboot';
export default middleware(req, res, next) {
const fb = new FastBoot({ distPath: distPath});
res.render('foo-bar', function(err, layoutHtml) {
const $layout = cheerio.load(layoutHtml);
fb.visit(req.url).then((result) => {
const app = result.instance;
const html = result.html();
const wormhole = app.lookup('service:wormhole');
get(wormhole, 'holes').forEach((hole) => {
$layout.find('#' + get(hole, 'to')).append(get(hole, 'html'));
});
// todo: also append the ember app!
});
});
}
export default Service.extend({
holes: computed(function() {
return Ember.A();
}),
register(hole) {
get(this, 'holes').pushObject({
html: hole.$().html(), // <- I'm sure line won't work
to: get(hole, 'to')
});
}
});
export default Component.extend({
wormhole: inject.service(),
_appendToDestination() {
const ret = this._super(...arguments);
if (typeof FastBoot !== 'undefined') {
get(this, 'wormhole').register(this);
}
return ret;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment