Skip to content

Commit bd2ae3d

Browse files
authored
Merge pull request #61 from simplabs/set-host-and-port
allow easy setting of host and port
2 parents 221bdd7 + 2d6f768 commit bd2ae3d

6 files changed

Lines changed: 35 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ const FastBootAppServer = require('fastboot-app-server');
3838

3939
let server = new FastBootAppServer({
4040
distPath: 'dist',
41-
gzip: true // Optional - Enables gzip compression.
41+
gzip: true, // Optional - Enables gzip compression.
42+
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).
4244
});
4345

4446
server.start();

src/express-http-server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class ExpressHTTPServer {
1515
this.password = options.password;
1616
this.cache = options.cache;
1717
this.gzip = options.gzip || false;
18+
this.host = options.host;
19+
this.port = options.port;
1820
this.beforeMiddleware = options.beforeMiddleware || noop;
1921
this.afterMiddleware = options.afterMiddleware || noop;
2022

@@ -54,7 +56,7 @@ class ExpressHTTPServer {
5456
this.afterMiddleware(app);
5557

5658
return new Promise(resolve => {
57-
let listener = app.listen(process.env.PORT || 3000, () => {
59+
let listener = app.listen(this.port || process.env.PORT || 3000, this.host || process.env.HOST, () => {
5860
let host = listener.address().address;
5961
let port = listener.address().port;
6062

src/fastboot-app-server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class FastBootAppServer {
1616
this.cache = options.cache;
1717
this.ui = options.ui;
1818
this.gzip = options.gzip;
19+
this.host = options.host;
20+
this.port = options.port;
1921
this.username = options.username;
2022
this.password = options.password;
2123
this.httpServer = options.httpServer;
@@ -35,6 +37,8 @@ class FastBootAppServer {
3537
distPath: this.distPath || process.env.FASTBOOT_DIST_PATH,
3638
cache: this.cache,
3739
gzip: this.gzip,
40+
host: this.host,
41+
port: this.port,
3842
username: this.username,
3943
password: this.password,
4044
httpServer: this.httpServer,

src/worker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Worker {
1111
this.ui = options.ui;
1212
this.cache = options.cache;
1313
this.gzip = options.gzip;
14+
this.host = options.host;
15+
this.port = options.port;
1416
this.username = options.username;
1517
this.password = options.password;
1618
this.beforeMiddleware = options.beforeMiddleware;
@@ -22,6 +24,8 @@ class Worker {
2224
distPath: this.distPath,
2325
cache: this.cache,
2426
gzip: this.gzip,
27+
host: this.host,
28+
port: this.port,
2529
username: this.username,
2630
password: this.password,
2731
beforeMiddleware: this.beforeMiddleware,

test/app-server-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ describe("FastBootAppServer", function() {
102102
});
103103
});
104104

105+
it("responds on the configured host and port", function() {
106+
return runServer('ipv4-app-server')
107+
.then(() => request('http://127.0.0.1:4100/'))
108+
.then((response) => {
109+
expect(response.statusCode).to.equal(200);
110+
expect(response.body).to.contain('Welcome to Ember');
111+
});
112+
});
113+
105114
});
106115

107116
function runServer(name) {

test/fixtures/ipv4-app-server.js

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

0 commit comments

Comments
 (0)