Permalink
Browse files

fix and example of basicAuth

  • Loading branch information...
1 parent 51cf03b commit 751ba3e9437eef30f0163d97fd5015106ec53781 @mvrilo committed Dec 4, 2011
Showing with 21 additions and 4 deletions.
  1. +9 −0 examples/basic-auth.js
  2. +12 −4 lib/frank.js
View
@@ -0,0 +1,9 @@
+var frank = require('../lib/frank'),
+ server = frank();
+
+server
+ .get('/')
+ .basicAuth('admin', 'admin')
+ .send('not so minimal api ftw too');
+
+server.listen(8000)
View
@@ -47,13 +47,21 @@ frank.server = function() {
server.use(connect.favicon());
for (var key in this.handler) {
- if (this.handler[key].auth) server.use(this.handler[key].basicAuth);
+ var path = this.handler[key].path,
+ auth = this.handler[key].auth,
+ callback = this.handler[key].callback;
- if (this.handler[key].callback) {
- server.use(this.handler[key].path, this.handler[key].callback);
+ if (auth) {
+ server.use(path, connect.basicAuth(function(user, pwd) {
+ return auth[0] === user && auth[1] === pwd;
+ }));
+ }
+
+ if (callback) {
+ server.use(path, callback);
}
else {
- server.use(this.handler[key].path, function(req, res) {
+ server.use(path, function(req, res) {
if (req.method == self.handler[key].method) {
res.end(self.handler[key].body);
}

0 comments on commit 751ba3e

Please sign in to comment.