diff --git a/index.js b/index.js index 3b9a008..e6ba875 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,17 @@ 'use strict'; const premberConfig = require('./lib/config'); +const path = require('path'); +const fs = require('fs'); module.exports = { name: require('./package').name, premberConfig, + included(app) { + this.fastbootOptions = fastbootOptionsFor(app.env, app.project); + }, + postprocessTree(type, tree) { if (type !== 'all') { return tree; @@ -39,6 +45,8 @@ module.exports = { return tree; } + config.fastbootOptions = this.fastbootOptions; + let Prerender = require('./lib/prerender'); let BroccoliDebug = require('broccoli-debug'); let Merge = require('broccoli-merge-trees'); @@ -96,3 +104,12 @@ function loadPremberPlugins(context) { return premberPlugin; }); } + +function fastbootOptionsFor(environment, project) { + const configPath = path.join(path.dirname(project.configPath()), 'fastboot.js'); + + if (fs.existsSync(configPath)) { + return require(configPath)(environment); + } + return {}; +} diff --git a/lib/prerender.js b/lib/prerender.js index 7ec6e69..6c93cb3 100644 --- a/lib/prerender.js +++ b/lib/prerender.js @@ -18,7 +18,7 @@ const port = 7784; class Prerender extends Plugin { constructor( builtAppTree, - { urls, indexFile, emptyFile }, + { urls, indexFile, emptyFile, fastbootOptions }, ui, plugins, rootURL @@ -33,6 +33,7 @@ class Prerender extends Plugin { this.protocol = protocol; this.port = port; this.host = `localhost:${port}`; + this.fastbootOptions = fastbootOptions || {}; } async listUrls(app, protocol, host) { @@ -111,9 +112,9 @@ class Prerender extends Plugin { JSON.stringify(pkg) ); - let app = new FastBoot({ + let app = new FastBoot(Object.assign({}, this.fastbootOptions, { distPath: this.inputPaths[0], - }); + })); let expressServer = express() .use(this.rootURL, express.static(this.inputPaths[0]))