Skip to content

Commit 87bdbc6

Browse files
Expose distPath on reload event (#96)
1 parent bc36d74 commit 87bdbc6

7 files changed

Lines changed: 64 additions & 5 deletions

File tree

src/fastboot-app-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class FastBootAppServer {
146146
}
147147

148148
reload() {
149-
this.broadcast({ event: 'reload' });
149+
this.broadcast({ event: 'reload', distPath: this.distPath });
150150
}
151151

152152
forkWorkers() {

src/worker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class Worker {
5959
handleMessage(message) {
6060
switch (message.event) {
6161
case 'reload':
62-
this.fastboot.reload();
62+
this.distPath = message.distPath || this.distPath;
63+
this.ui.writeLine('Reloading the application from distPath:', this.distPath);
64+
this.fastboot.reload({ distPath: this.distPath });
6365
break;
6466
case 'error':
6567
this.error = message.error;

test/app-server-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ describe("FastBootAppServer", function() {
119119
expect(response.body).to.contain('Welcome to Ember from MY GLOBAL!');
120120
});
121121
});
122+
123+
it("allows changing of distpath", function() {
124+
return runServer('dist-path-change-server')
125+
.then(() => request('http://localhost:3000/'))
126+
.then((response) => {
127+
expect(response.statusCode).to.equal(200);
128+
expect(response.body).to.contain('Welcome to Ember from MY GLOBAL!');
129+
});
130+
});
122131
});
123132

124133
function runServer(name) {

test/fixtures/basic-app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<title>FastbootTest</title>
6+
<title>FastbootTest - basic</title>
77
<meta name="description" content="">
88
<meta name="viewport" content="width=device-width, initial-scale=1">
99

test/fixtures/broken-app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<title>FastbootTest</title>
6+
<title>FastbootTest - broken</title>
77
<meta name="description" content="">
88
<meta name="viewport" content="width=device-width, initial-scale=1">
99

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const FastBootAppServer = require('../../src/fastboot-app-server');
5+
6+
const MY_GLOBAL = 'MY GLOBAL';
7+
8+
class DownloaderNotifier {
9+
constructor(options) {
10+
this.distPath = options.distPath;
11+
this.subscriptions = [];
12+
}
13+
14+
subscribe(handler) {
15+
this.subscriptions.push(handler);
16+
return Promise.resolve();
17+
}
18+
19+
trigger() {
20+
this.distPath = path.resolve(__dirname, './global-app');
21+
this.subscriptions.forEach(handler => {
22+
handler();
23+
});
24+
}
25+
26+
download() {
27+
return Promise.resolve(this.distPath);
28+
}
29+
}
30+
31+
const connector = new DownloaderNotifier({
32+
distPath: path.resolve(__dirname, './basic-app')
33+
});
34+
35+
var server = new FastBootAppServer({
36+
notifier: connector,
37+
downloader: connector,
38+
sandboxGlobals: { THE_GLOBAL: MY_GLOBAL }
39+
});
40+
41+
const serverPromise = server.start();
42+
43+
// Don't run this on worker threads.
44+
if (serverPromise) {
45+
serverPromise.then(() => {
46+
connector.trigger();
47+
});
48+
}

test/fixtures/global-app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<title>FastbootTest</title>
6+
<title>FastbootTest - global</title>
77
<meta name="description" content="">
88
<meta name="viewport" content="width=device-width, initial-scale=1">
99

0 commit comments

Comments
 (0)