Skip to content

Commit

Permalink
Add repo handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Jun 1, 2017
1 parent fc66594 commit 407acf5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 21 additions & 0 deletions app/handlers/repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
exports = module.exports = function() {
var request = require('superagent');


var repo = null;

function respond(req, res, next) {
if (repo) { return res.status(200).json(repo); }
var url = 'https://api.github.com/repos/jaredhanson/passport';
request.get(url, function (err, resp) {
if (err) { return res.status(resp.status).json(resp.body); };
repo = resp.body;
res.status(200).json(repo);
setTimeout(function () { repo = null; }, 24 * 60 * 1000);
});
}

return [ respond ];
};

exports['@require'] = [];
6 changes: 4 additions & 2 deletions app/service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports = module.exports = function(homeHandler, docsService, featuresHandler) {
exports = module.exports = function(homeHandler, docsService, featuresHandler, repoHandler) {
var express = require('express');
var path = require('path');

Expand Down Expand Up @@ -28,6 +28,7 @@ exports = module.exports = function(homeHandler, docsService, featuresHandler) {
service.get('/', homeHandler);
service.use('/docs', docsService);
service.get('/features', featuresHandler);
service.get('/repo.json', repoHandler)

return service;
};
Expand All @@ -36,5 +37,6 @@ exports['@implements'] = 'http://i.bixbyjs.org/http/Service';
exports['@require'] = [
'./handlers/home',
'./handlers/docs',
'./handlers/features'
'./handlers/features',
'./handlers/repo'
];

0 comments on commit 407acf5

Please sign in to comment.