Skip to content

Commit

Permalink
Resubmitting OpenUserJS#318
Browse files Browse the repository at this point in the history
* Show the raw npm ls JSON data for the server

Applies to OpenUserJS#296

This appears to be the only way it can be done for listing the current dependencies. I haven't found any native API to Node.js that does this... so I'm willing to give this a whirl.
  • Loading branch information
Martii committed Aug 23, 2014
1 parent 2663aae commit a013abe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ app.get('/admin/authas', admin.authAsUser);
app.get('/admin/json', admin.adminJsonView);
app.get('/admin/user/:id', admin.adminUserView);
app.get('/admin/api', admin.adminApiKeysPage);
app.get('/admin/npmls', admin.adminNpmLsView);
app.post('/admin/api/update', admin.apiAdminUpdate);

// Moderation routes
Expand Down
23 changes: 23 additions & 0 deletions controllers/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var async = require('async');
var exec = require('child_process').exec;

var Comment = require('../models/comment').Comment;
var Discussion = require('../models/discussion').Discussion;
Expand Down Expand Up @@ -289,6 +290,28 @@ exports.adminApiKeysPage = function (aReq, aRes, aNext) {
});
};

// View everything about current modules for the server
// This is mostly for debugging in production
exports.adminNpmLsView = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

//
var options = {};

// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

if (!options.isAdmin)
return aRes.send(403, { status: 403, message: 'Not an admin.' });

exec('npm ls --json', function(aErr, aStdout, aStderr) {
if (aErr) return aRes.send(501, { status: 501, message: 'Not implemented.' });
aRes.json(JSON.parse(aStdout));
});
}

// Manage oAuth strategies without having to restart the server
// When new keys are added, we load the new strategy
// When keys are removed, we remove the strategy
Expand Down
3 changes: 3 additions & 0 deletions views/pages/adminPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<a href="/admin/api" class="list-group-item">
API Keys
</a>
<a href="/admin/npmls" class="list-group-item">
Raw <code>npm ls --json</code> Data
</a>
</div>
</div>
</div>
Expand Down

0 comments on commit a013abe

Please sign in to comment.