Skip to content

Instantly share code, notes, and snippets.

@piscis
Created January 15, 2011 10:00
Show Gist options
  • Save piscis/780815 to your computer and use it in GitHub Desktop.
Save piscis/780815 to your computer and use it in GitHub Desktop.
Protecting express via connect basic auth plugin
var express = require('express');
var app = express.createServer();
// User validation
var auth = express.basicAuth(function(user, pass) {
return (user==pass) ? true : false;
},'Admin Area');
app.get('/hello', auth, function(req,res) {
res.writeHead("200");
res.end("Htaccess protected page");
});
app.get('/',function(req,res){
res.writeHead("200");
res.end("None protected page");
})
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment