Skip to content

Commit 2b73cdf

Browse files
committed
expose sandboxGlobals option via FastBootAppServer
1 parent c6152ad commit 2b73cdf

11 files changed

Lines changed: 87837 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ Put the following in a `server.js` file:
3636
```js
3737
const FastBootAppServer = require('fastboot-app-server');
3838

39+
const MY_GLOBAL = 'MY GLOBAL';
40+
3941
let server = new FastBootAppServer({
4042
distPath: 'dist',
4143
gzip: true, // Optional - Enables gzip compression.
4244
host: '0.0.0.0', // Optional - Sets the host the server listens on.
43-
port: 4000 // Optional - Sets the port the server listens on (defaults to the PORT env var or 3000).
45+
port: 4000, // Optional - Sets the port the server listens on (defaults to the PORT env var or 3000).
46+
sandboxGlobals: { GLOBAL_VALUE: MY_GLOBAL } // Optional - Make values available to the Ember app running in the FastBoot server, e.g. "MY_GLOBAL" will be available as "GLOBAL_VALUE"
4447
});
4548

4649
server.start();

src/fastboot-app-server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FastBootAppServer {
2323
this.httpServer = options.httpServer;
2424
this.beforeMiddleware = options.beforeMiddleware;
2525
this.afterMiddleware = options.afterMiddleware;
26+
this.sandboxGlobals = options.sandboxGlobals;
2627

2728
if (!this.ui) {
2829
let UI = require('./ui');
@@ -43,7 +44,8 @@ class FastBootAppServer {
4344
password: this.password,
4445
httpServer: this.httpServer,
4546
beforeMiddleware: this.beforeMiddleware,
46-
afterMiddleware: this.afterMiddleware
47+
afterMiddleware: this.afterMiddleware,
48+
sandboxGlobals: this.sandboxGlobals
4749
});
4850

4951
this.worker.start();

src/worker.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Worker {
1717
this.password = options.password;
1818
this.beforeMiddleware = options.beforeMiddleware;
1919
this.afterMiddleware = options.afterMiddleware;
20+
this.sandboxGlobals = options.sandboxGlobals;
2021

2122
if (!this.httpServer) {
2223
this.httpServer = new ExpressHTTPServer({
@@ -30,6 +31,7 @@ class Worker {
3031
password: this.password,
3132
beforeMiddleware: this.beforeMiddleware,
3233
afterMiddleware: this.afterMiddleware,
34+
sandboxGlobals: options.sandboxGlobals,
3335
});
3436
}
3537

@@ -70,6 +72,7 @@ class Worker {
7072
buildMiddleware() {
7173
this.fastboot = new FastBoot({
7274
distPath: this.distPath,
75+
sandboxGlobals: this.sandboxGlobals,
7376
});
7477

7578
return fastbootMiddleware({

test/app-server-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ describe("FastBootAppServer", function() {
111111
});
112112
});
113113

114+
it("allows setting sandbox globals", function() {
115+
return runServer('sandbox-globals-app-server')
116+
.then(() => request('http://localhost:3000/'))
117+
.then((response) => {
118+
expect(response.statusCode).to.equal(200);
119+
expect(response.body).to.contain('Welcome to Ember from MY GLOBAL!');
120+
});
121+
});
114122
});
115123

116124
function runServer(name) {

0 commit comments

Comments
 (0)