Skip to content

Commit

Permalink
apply config/fastboot.js the same way that ember-cli-fastboot does
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed May 5, 2023
1 parent ae7f9aa commit 86fe0f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 {};
}
7 changes: 4 additions & 3 deletions lib/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const port = 7784;
class Prerender extends Plugin {
constructor(
builtAppTree,
{ urls, indexFile, emptyFile },
{ urls, indexFile, emptyFile, fastbootOptions },
ui,
plugins,
rootURL
Expand All @@ -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) {
Expand Down Expand Up @@ -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]))
Expand Down

0 comments on commit 86fe0f8

Please sign in to comment.