Skip to content

Commit 651ae7d

Browse files
authored
Merge pull request #26 from bobisjan/allow-basic-auth
Allow to enable Basic Authentication from FastBoot App Server
2 parents 9462c0c + 44739bd commit 651ae7d

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,14 @@ The `subscribe()` method on your notifier is passed a `notify` function.
211211
If you detect that a new version of your app has been deployed (whether
212212
via polling or a push notification), call this function to trigger a
213213
reload.
214+
215+
## Basic Authentication
216+
217+
You can enable Basic Authentication by providing `username` and `password` options:
218+
219+
```js
220+
let server = new FastBootAppServer({
221+
username: 'tomster',
222+
password: 'zoey'
223+
});
224+
```

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.username = options.username;
20+
this.password = options.password;
1921
this.httpServer = options.httpServer;
2022
this.beforeMiddleware = options.beforeMiddleware;
2123
this.afterMiddleware = options.afterMiddleware;
@@ -33,6 +35,8 @@ class FastBootAppServer {
3335
distPath: this.distPath || process.env.FASTBOOT_DIST_PATH,
3436
cache: this.cache,
3537
gzip: this.gzip,
38+
username: this.username,
39+
password: this.password,
3640
httpServer: this.httpServer,
3741
beforeMiddleware: this.beforeMiddleware,
3842
afterMiddleware: this.afterMiddleware

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.username = options.username;
15+
this.password = options.password;
1416
this.beforeMiddleware = options.beforeMiddleware;
1517
this.afterMiddleware = options.afterMiddleware;
1618

@@ -20,6 +22,8 @@ class Worker {
2022
distPath: this.distPath,
2123
cache: this.cache,
2224
gzip: this.gzip,
25+
username: this.username,
26+
password: this.password,
2327
beforeMiddleware: this.beforeMiddleware,
2428
afterMiddleware: this.afterMiddleware,
2529
});

test/app-server-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,21 @@ describe("FastBootAppServer", function() {
8686
.then(response => {
8787
expect(response.body).to.not.match(/error/);
8888
expect(response.headers['x-test-header']).to.equal('testing');
89+
});
90+
});
91+
92+
it("returns a 401 status code for non-authenticated request", function() {
93+
return runServer('auth-app-server')
94+
.then(() => request('http://localhost:3000/'))
95+
.then(response => {
96+
expect(response.statusCode).to.equal(401);
97+
expect(response.headers['www-authenticate']).equal('Basic realm=Authorization Required');
8998
})
99+
.then(() => request({ uri: 'http://localhost:3000/', headers: { 'Authorization': 'Basic dG9tc3Rlcjp6b2V5' }}))
100+
.then(response => {
101+
expect(response.statusCode).to.equal(200);
102+
expect(response.body).to.contain('Welcome to Ember');
103+
});
90104
});
91105

92106
});

test/fixtures/auth-app-server.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
var path = require('path');
4+
var alchemistRequire = require('broccoli-module-alchemist/require');
5+
var FastBootAppServer = alchemistRequire('fastboot-app-server');
6+
7+
var server = new FastBootAppServer({
8+
distPath: path.resolve(__dirname, './basic-app'),
9+
username: 'tomster',
10+
password: 'zoey'
11+
});
12+
13+
server.start();

0 commit comments

Comments
 (0)