From 41da09d65b29f45f7e532f0c83a027976a546461 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Fri, 5 May 2023 12:28:14 +0100 Subject: [PATCH] apply config/fastboot.js the same way that ember-cli-fastboot does --- index.js | 20 ++++++++++++++++++++ lib/prerender.js | 11 +++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 3b9a008..ec18784 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,15 @@ 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..81f917e 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,11 @@ class Prerender extends Plugin { JSON.stringify(pkg) ); - let app = new FastBoot({ - distPath: this.inputPaths[0], - }); + let app = new FastBoot( + Object.assign({}, this.fastbootOptions, { + distPath: this.inputPaths[0], + }) + ); let expressServer = express() .use(this.rootURL, express.static(this.inputPaths[0]))