Skip to content

Commit

Permalink
Update discovery mount point to be /drakov
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakov Khalinsky committed Jul 27, 2015
1 parent 86d9238 commit 2363cd5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 66 deletions.
2 changes: 1 addition & 1 deletion lib/arguments/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
description: 'Load configuration from a Javascript file, must export an object'
},
discover: {
description: 'List all available endpoints under `/`. If it\'s a module name, it will be required and called to create a middleware function to handle `/`.',
description: 'List all available endpoints under `/drakov`. If value of argument is a module name, it will be required and called to create a middleware function',
alias: 'D',
default: false
}
Expand Down
5 changes: 2 additions & 3 deletions lib/drakov.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ exports.run = function(argv, cb) {
server = setup.startServer(argv, app, cb);
if (argv.discover && typeof argv.discover === 'string') {
discoverabilityModule = require(argv.discover);
}
else {
} else {
app.set('views', 'views');
app.set('view engine', 'jade');
discoverabilityModule = require('./middleware/discover');
}
if (argv.discover) {
app.get('/', discoverabilityModule(argv));
app.get('/drakov', discoverabilityModule(argv));
}
});
};
Expand Down
23 changes: 10 additions & 13 deletions lib/middleware/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ var buildRouteMap = require('./route-map');
module.exports = function(sourceFiles) {
return function(req, res, next) {
if (res.headersSent) {
next();
}
else {
buildRouteMap(sourceFiles, function(err, routeMap) {
if (err) {
next(err);
}
else {
res.render('discover', {
routes: Object.keys(routeMap)
});
}
});
return next();
}
buildRouteMap(sourceFiles, function(err, routeMap) {
if (err) {
return next(err);
} else {
res.render('discover', {
routes: Object.keys(routeMap)
});
}
});
};
};
53 changes: 4 additions & 49 deletions test/api/discover-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ describe('Discover', function() {
helper.drakov.stop(done);
});

describe('/', function() {
describe('/drakov', function() {
describe('GET', function() {
it('should get discover page', function(done) {
request.get('/')
request.get('/drakov')
.expect(200)
.expect('Content-type', 'text/html; charset=utf-8')
.end(helper.endCb(done));
Expand All @@ -32,10 +32,10 @@ describe('Discover', function() {
helper.drakov.stop(done);
});

describe('/', function() {
describe('/drakov', function() {
describe('GET', function() {
it('should get 404', function(done) {
request.get('/')
request.get('/drakov')
.expect(404)
.end(helper.endCb(done));
});
Expand All @@ -44,49 +44,4 @@ describe('Discover', function() {
});
});

describe('Root-Level-API', function() {
describe('Discover option not specified', function() {
before(function(done) {
helper.drakov.run({sourceFiles: 'test/example/md/root-level-api.md'}, done);
});

after(function(done) {
helper.drakov.stop(done);
});

describe('/', function() {
describe('GET', function() {
it('should get root level request rather than discover page', function(done) {
request.get('/')
.expect(200)
.expect('Content-type', 'application/json;charset=UTF-8')
.expect({Slash: 'http://images5.fanpop.com/image/photos/31200000/Slash-slash-31278382-1707-2560.jpg'})
.end(helper.endCb(done));
});
});
});
});

describe('Discover option true', function() {
before(function(done) {
helper.drakov.run({sourceFiles: 'test/example/md/root-level-api.md', discover: true}, done);
});

after(function(done) {
helper.drakov.stop(done);
});

describe('/', function() {
describe('GET', function() {
it('should get root level request rather than discover page', function(done) {
request.get('/')
.expect(200)
.expect('Content-type', 'application/json;charset=UTF-8')
.expect({Slash: 'http://images5.fanpop.com/image/photos/31200000/Slash-slash-31278382-1707-2560.jpg'})
.end(helper.endCb(done));
});
});
});
});
});
});

0 comments on commit 2363cd5

Please sign in to comment.