Created
September 12, 2011 06:05
-
-
Save dawnerd/1210666 to your computer and use it in GitHub Desktop.
basic-auth example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
app = module.exports = express.createServer(); | |
//Basic-Auth config | |
var auth = require('basic-auth')({ | |
name: 'Test Auth', | |
accounts: [ | |
'test:password', | |
'test2:password2' | |
] | |
}).auth; | |
//configuration | |
app.configure(function(){ | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'jade'); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(app.router); | |
app.use(express.static(__dirname + '/public')); | |
}); | |
app.configure('development', function(){ | |
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | |
}); | |
app.configure('production', function(){ | |
app.use(express.errorHandler()); | |
}); | |
// Second param needs to be auth if you want to secure a page | |
app.get('/', auth, function(req, res){ | |
res.render('index', { | |
title: 'Express' | |
}); | |
}); | |
app.listen(3000); | |
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment