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 16, 2023
1 parent d10db93 commit b30be93
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
20 changes: 20 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,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 {};
}
11 changes: 7 additions & 4 deletions lib/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const port = 7784;
class Prerender extends Plugin {
constructor(
builtAppTree,
{ urls, indexFile, emptyFile },
{ urls, indexFile, emptyFile, fastbootOptions },
ui,
plugins,
rootURL
Expand All @@ -30,6 +30,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 @@ -108,9 +109,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]))
Expand Down

0 comments on commit b30be93

Please sign in to comment.