add comments and debug
This commit is contained in:
		
							parent
							
								
									5cecf3ea45
								
							
						
					
					
						commit
						0ffe4e2e5c
					
				@ -5,18 +5,18 @@ var PromiseA = require('bluebird');
 | 
				
			|||||||
module.exports.inject = function (app) {
 | 
					module.exports.inject = function (app) {
 | 
				
			||||||
  //var jwsUtils = require('./lib/jws-utils').create(signer);
 | 
					  //var jwsUtils = require('./lib/jws-utils').create(signer);
 | 
				
			||||||
  var CORS = require('connect-cors');
 | 
					  var CORS = require('connect-cors');
 | 
				
			||||||
 | 
					  var cors = CORS({ credentials: true, headers: [
 | 
				
			||||||
  // Allows CORS access to API with ?access_token=
 | 
					 | 
				
			||||||
  // TODO Access-Control-Max-Age: 600
 | 
					 | 
				
			||||||
  // TODO How can we help apps handle this? token?
 | 
					 | 
				
			||||||
  // TODO allow apps to configure trustedDomains, auth, etc
 | 
					 | 
				
			||||||
  app.use('/', CORS({ credentials: true, headers: [
 | 
					 | 
				
			||||||
    'X-Requested-With'
 | 
					    'X-Requested-With'
 | 
				
			||||||
  , 'X-HTTP-Method-Override'
 | 
					  , 'X-HTTP-Method-Override'
 | 
				
			||||||
  , 'Content-Type'
 | 
					  , 'Content-Type'
 | 
				
			||||||
  , 'Accept'
 | 
					  , 'Accept'
 | 
				
			||||||
  , 'Authorization'
 | 
					  , 'Authorization'
 | 
				
			||||||
  ], methods: [ "GET", "POST", "PATCH", "PUT", "DELETE" ] }));
 | 
					  ], methods: [ "GET", "POST", "PATCH", "PUT", "DELETE" ] });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Allows CORS access to API with ?access_token=
 | 
				
			||||||
 | 
					  // TODO Access-Control-Max-Age: 600
 | 
				
			||||||
 | 
					  // TODO How can we help apps handle this? token?
 | 
				
			||||||
 | 
					  // TODO allow apps to configure trustedDomains, auth, etc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //function weakDecipher(secret, val) { return require('./weak-crypt').weakDecipher(val, secret); }
 | 
					  //function weakDecipher(secret, val) { return require('./weak-crypt').weakDecipher(val, secret); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -82,7 +82,13 @@ module.exports.inject = function (app) {
 | 
				
			|||||||
      if (!data) {
 | 
					      if (!data) {
 | 
				
			||||||
        err = new Error('not a json web token');
 | 
					        err = new Error('not a json web token');
 | 
				
			||||||
        err.code = 'E_NOT_JWT';
 | 
					        err.code = 'E_NOT_JWT';
 | 
				
			||||||
        return PromiseA.reject(err);
 | 
					        res.send({
 | 
				
			||||||
 | 
					          error: err.code
 | 
				
			||||||
 | 
					        , error_description: err.message
 | 
				
			||||||
 | 
					        , error_url: 'https://oauth3.org/docs/errors#' + (err.code || 'E_UNKNOWN_EXCEPTION')
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        // PromiseA.reject(err);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      req.oauth3.token = token;
 | 
					      req.oauth3.token = token;
 | 
				
			||||||
@ -91,5 +97,12 @@ module.exports.inject = function (app) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /*
 | 
				
			||||||
 | 
					  app.use('/', function (req, res, next) {
 | 
				
			||||||
 | 
					    console.log('[DEBUG CORS]', req.method, req.hostname, req.url);
 | 
				
			||||||
 | 
					    cors(req, res, next);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  app.use('/', getToken);
 | 
					  app.use('/', getToken);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -158,10 +158,12 @@ function getApi(pkgConf, pkgDeps, packagedApi) {
 | 
				
			|||||||
      require('./oauth3-auth').inject(packagedApi._api, pkgConf, pkgDeps);
 | 
					      require('./oauth3-auth').inject(packagedApi._api, pkgConf, pkgDeps);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // DEBUG
 | 
					      // DEBUG
 | 
				
			||||||
 | 
					      /*
 | 
				
			||||||
      packagedApi._api.use('/', function (req, res, next) {
 | 
					      packagedApi._api.use('/', function (req, res, next) {
 | 
				
			||||||
        console.log('[DEBUG pkgsrv]', req.method, req.hostname, req.url);
 | 
					        console.log('[DEBUG pkgsrv]', req.method, req.hostname, req.url);
 | 
				
			||||||
        next();
 | 
					        next();
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
					      */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // TODO fix backwards compat
 | 
					      // TODO fix backwards compat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -249,6 +251,7 @@ function runApi(opts, router, req, res, next) {
 | 
				
			|||||||
  // TODO compile packagesMap
 | 
					  // TODO compile packagesMap
 | 
				
			||||||
  // TODO people may want to use the framework in a non-framework way (i.e. to conceal the module name)
 | 
					  // TODO people may want to use the framework in a non-framework way (i.e. to conceal the module name)
 | 
				
			||||||
  router.packagedApis.some(function (_packagedApi) {
 | 
					  router.packagedApis.some(function (_packagedApi) {
 | 
				
			||||||
 | 
					    // console.log('[DEBUG _packagedApi.id]', _packagedApi.id);
 | 
				
			||||||
    var pathname = router.pathname;
 | 
					    var pathname = router.pathname;
 | 
				
			||||||
    if ('/' === pathname) {
 | 
					    if ('/' === pathname) {
 | 
				
			||||||
      pathname = '';
 | 
					      pathname = '';
 | 
				
			||||||
@ -306,7 +309,7 @@ function runApi(opts, router, req, res, next) {
 | 
				
			|||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  console.log("[DEBUG pkgpath]", pkgConf.apipath, packagedApi.id);
 | 
					  // console.log("[DEBUG pkgpath]", pkgConf.apipath, packagedApi.id);
 | 
				
			||||||
  loadApi(pkgConf, pkgDeps, packagedApi).then(function (api) {
 | 
					  loadApi(pkgConf, pkgDeps, packagedApi).then(function (api) {
 | 
				
			||||||
    api(req, res, next);
 | 
					    api(req, res, next);
 | 
				
			||||||
  }, function (err) {
 | 
					  }, function (err) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user