How to use the express.basicAuth function in express

To help you get started, we’ve selected a few express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mil-tokyo / sashimi / distributor / src / app.js View on Github external
// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

/*
process.on('uncaughtException', function (err) {
	console.error(err.stack);
});
*/

app.get('/', routes.index);
app.get('/about', about.index);
app.get(
	'/management',
	express.basicAuth(function(user, password) {
		return user === config.auth.user && password === config.auth.password;
	}
	),
	management.index
);
app.post('/management/run_code', management.run_code);
app.post('/management/kill_project', management.kill_project);
app.get('/management/ongoing_projects', management.ongoing_projects);
app.get('/management/connected_clients_num', management.connected_clients_num);
app.get('/management/connected_clients', management.connected_clients);
app.get('/framework', framework.index);
app.post('/api', api.index);

app.use(express.static(__dirname + '/public'));

if (cluster.isMaster) {
github rawgraphs / raw / raw.js View on Github external
app.use(express.static(path.join(__dirname, 'components')));
app.use(app.router);
app.use(express.favicon(path.join(__dirname, 'public/img/favicon.ico'))); 

// development only
if (app.get('env') === 'development') {
  app.use(express.errorHandler());
}

// production only
if (app.get('env') === 'production') {
  // TODO
};

// Authenticator
var auth = express.basicAuth('test', 'test')

/**
 * Routes
 */

// serve index and view partials
app.get('/', auth, routes.index);
app.get('/partials/:name', routes.partials);

// redirect all others to the index (HTML5 history)
app.get('*', auth, routes.index);


/**
 * Start Server
 */
github 29decibel / bean-note / server / app.js View on Github external
app.configure(function(){
  app.use(express.bodyParser());
  app.use(express.cookieParser());

  // basic auth
  app.use(express.basicAuth(username, password));

  // static public folder
  app.use(express.static('public'))
});
github racker / dreadnot / lib / web / app.js View on Github external
exports.registerAPI = function(dreadnot, authdb) {
  var app = express.createServer(),
      apiHandlers = handlers.api.getAPIHandlers(dreadnot),
      basic;

  // API is behind Basic auth
  basic = express.basicAuth(function(username, password, callback) {
    authdb.validate(username, password, function(err, valid) {
      if (err || !valid) {
        callback(err, null);
      } else {
        callback(null, new User(true, username));
      }
    });
  });

  app.configure(function() {
    app.use(basic);
    app.use(middleware.apiresponse());
  });

  // Register handlers
  app.get('/1.0', apiHandlers.getDreadnot);
github FWeinb / nodeshot / nodeshot-server / app.js View on Github external
// Basic configuration

if (config.server.cors){
  app.use(function(req, res, next) {
      res.header('Access-Control-Allow-Origin', '*');
      res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
      res.header('Access-Control-Allow-Headers', 'Content-Type');

      next();
  });
}

// Add kue
if ( config.server.kue.show ){
  app.use('/kue', express.basicAuth(config.server.kue.username, config.server.kue.password));
  app.use('/kue', kue.app);
}

app.use(app.router);

// Handle errors
app.use(function(err, req, res, next){

  winston.info(err);

  res.writeHead(500, {"Content-Type" : "application/json"});
  res.end(JSON.stringify({
    request : 'failed',
    reason : ''+err
  }));
});
github mozilla / MakeAPI / test / fake / FakeAPI.js View on Github external
function startFakeAPI() {
      habitat.load();

      var app = express(),
          env = new habitat(),
          routes = require( "../../routes/make.js" )( Fake, env ),
          middleware = require( "../../lib/middleware.js" )( env );

      app.use( express.logger( "dev" ) );
      app.use( express.bodyParser() );

      app.post( "/api/make", express.basicAuth( middleware.authenticateUser ),
                             middleware.prefixAuth,
                             routes.create );
      app.put( "/api/make/:id", express.basicAuth( middleware.authenticateUser ),
                                middleware.prefixAuth, routes.update );
      app.del( "/api/make/:id", express.basicAuth( middleware.authenticateUser ),
                                middleware.prefixAuth, routes.remove );
      app.get( "/api/makes/search", function crossOrigin( req, res, next ) {
        res.header( "Access-Control-Allow-Origin", "*" );
        next();
      }, routes.search );
      app.options( "/api/makes/search", function( req, res ) {
        res.header( "Access-Control-Allow-Origin", "*" );
        res.header( "Access-Control-Allow-Headers", "Content-Type" );
        res.send( 200 );
      });
github khilnani / supercollider.web / supercollider.web.js View on Github external
app.configure(function () {
		if( config.username ) {
			app.use(
			express.basicAuth( config.username , config.password  )
			)
		} else {
			log.system("Skipping basic auth.");
		}
		app.set("view options", {layout: false});
		app.use(express.static(__dirname + '/html'));
		app.use(express.bodyParser());
	});
github breach / gig.fs / store / store.js View on Github external
app.configure(function() {
    app.use('/admin', express.basicAuth('admin', common.KEY)); 
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(access.verify);
    app.use(app.router);
    app.use(access.error);
  });
github modera / mcloud / mcloud / static_old / components / term.js / example / index.js View on Github external
app.use(function(req, res, next) {
  var setHeader = res.setHeader;
  res.setHeader = function(name) {
    switch (name) {
      case 'Cache-Control':
      case 'Last-Modified':
      case 'ETag':
        return;
    }
    return setHeader.apply(res, arguments);
  };
  next();
});

app.use(express.basicAuth(function(user, pass, next) {
  if (user !== 'foo' || pass !== 'bar') {
    return next(true);
  }
  return next(null, user);
}));

app.use(express.static(__dirname));
app.use(terminal.middleware());

server.listen(8080);

server.on('connection', function(socket) {
  var address = socket.remoteAddress;
  if (address !== '127.0.0.1' && address !== '::1') {
    try {
      socket.destroy();
github arizzitano / petbot / remote / petbot.js View on Github external
app.configure(function () {
    var username = process.env.AUTH_USERNAME;
    var password = process.env.AUTH_PASSWORD;
    if (username != null && password != null) {
        app.use(express.basicAuth(username, password));
    }
    app.use(express.static(__dirname + '/../public'));
});