Skip to content

Commit 0b9690e

Browse files
committed
Serve static assets
1 parent f576e19 commit 0b9690e

11 files changed

Lines changed: 84154 additions & 0 deletions

File tree

lib/express-http-server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ExpressHTTPServer {
88
options = options || {};
99

1010
this.ui = options.ui;
11+
this.distPath = options.distPath;
1112
this.username = options.username;
1213
this.password = options.password;
1314
this.cache = options.cache;
@@ -29,6 +30,11 @@ class ExpressHTTPServer {
2930
app.get('/*', this.buildCacheMiddleware());
3031
}
3132

33+
if (this.distPath) {
34+
app.get('/', middleware);
35+
app.use(express.static(this.distPath));
36+
}
37+
3238
app.get('/*', middleware);
3339

3440
return new Promise(resolve => {

lib/fastboot-app-server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class FastBootAppServer {
5757
});
5858
}
5959

60+
stop() {
61+
this.broadcast({ event: 'shutdown' });
62+
}
63+
6064
propagateUI() {
6165
if (this.downloader) { this.downloader.ui = this.ui; }
6266
if (this.notifier) { this.notifier.ui = this.ui; }

lib/worker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Worker {
1414
if (!this.httpServer) {
1515
this.httpServer = new ExpressHTTPServer({
1616
ui: this.ui,
17+
distPath: this.distPath,
1718
cache: this.cache
1819
});
1920
}
@@ -42,6 +43,9 @@ class Worker {
4243
case 'error':
4344
this.error = message.error;
4445
break;
46+
case 'shutdown':
47+
process.exit(0);
48+
break;
4549
}
4650
}
4751

test/app-server-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ describe("FastBootAppServer", function() {
4141
});
4242
});
4343

44+
it("serves static assets", function() {
45+
return runServer('basic-app-server')
46+
.then(() => request('http://localhost:3000/assets/fastboot-test.js'))
47+
.then(response => {
48+
expect(response.statusCode).to.equal(200);
49+
expect(response.body).to.contain('"use strict";');
50+
})
51+
.then(() => request('http://localhost:3000/'))
52+
.then(response => {
53+
expect(response.statusCode).to.equal(200);
54+
expect(response.body).to.contain('Welcome to Ember');
55+
});
56+
});
57+
4458
});
4559

4660
function runServer(name) {
@@ -61,5 +75,9 @@ function runServer(name) {
6175
server.stderr.on('data', data => {
6276
console.log(data.toString());
6377
});
78+
79+
server.stdout.on('data', data => {
80+
console.log(data.toString());
81+
});
6482
});
6583
}

test/fixtures/basic-app-server.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const FastBootAppServer = require('../../lib/fastboot-app-server.js');
5+
6+
let server = new FastBootAppServer({
7+
distPath: path.resolve(__dirname, './basic-app')
8+
});
9+
10+
server.start();

0 commit comments

Comments
 (0)