Amazon Lambda HTTP Basic Auth using ClaudiaJS

var ApiBuilder = require('claudia-api-builder'),
    api        = module.exports = new ApiBuilder(),
    renderPage = function (body) {
      'use strict';
      return body;
    };

const authUser   = 'user',
      authPass   = 'pass',
      authString = 'Basic ' + new Buffer(authUser + ':' + authPass).toString('base64');


api.get('/', function(req) {
  'use strict';

  var headers  = req.headers;

  if ( ('Authorization' in headers) && (headers['Authorization'] === authString) ) {
    return {"status":200, "statusDescription":"Authorized"};
  } else {
    throw new ApiBuilder.ApiResponse({"status":401, "statusDescription":"Unauthorized"}, {'Content-Type':'application/json'}, 401);
  } // if

}, { success: { code:200, headers:{'X-Version':'0.0.1','WWW-Authenticate':'Basic'}, contentType: 'application/json'},
     error:   { code:500, headers:{'X-Version':'0.0.1','WWW-Authenticate':'Basic'}, contentType: 'application/json'},
     apiKeyRequired: false
   });
categories: lambda | claudiajs |