From bad7aee4ec8d73363a781a6ecd93260b1a50b4ea Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 5 Dec 2014 04:53:37 +0300 Subject: [PATCH] use /-/whoami endpoint instead of /whoami Allows to get rid of referer magic, so it's a nice change to have. See this issue for details: https://github.com/npm/npm-registry-client/issues/88 --- lib/index-api.js | 3 +++ test/functional/basic.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/index-api.js b/lib/index-api.js index ae84bd7c4..65f5b8a1d 100644 --- a/lib/index-api.js +++ b/lib/index-api.js @@ -41,6 +41,9 @@ module.exports = function(config, auth, storage) { next('route') } }) + app.get('/-/whoami', function(req, res, next) { + next({ username: req.remote_user.name }) + }) // TODO: anonymous user? app.get('/:package/:version?', can('access'), function(req, res, next) { diff --git a/test/functional/basic.js b/test/functional/basic.js index 8aedb89ae..6bb526ec5 100644 --- a/test/functional/basic.js +++ b/test/functional/basic.js @@ -129,5 +129,13 @@ module.exports = function() { cb() }) }) + + it('who am I?', function(cb) { + server.request({uri:'/-/whoami'}, function(err, res, body) { + assert.equal(res.statusCode, 200) + assert.equal(body.username, 'test') + cb() + }) + }) }