add http listing

This commit is contained in:
AJ ONeal 2018-01-10 01:25:56 -07:00
parent 66a267090b
commit 96dd311fc5
5 changed files with 12 additions and 7 deletions

View File

@ -97,6 +97,7 @@ cli.main(function (args, cli) {
}
var engine;
var path = require('path');
var engineOpts = { filepath: path.resolve(cli.input) };
var dnsd = {};
dnsd.onMessage = function (nb, cb) {
@ -367,7 +368,6 @@ cli.main(function (args, cli) {
}
// TODO get local answer first, if available
var path = require('path');
if (!cli.input) {
console.warn('[WARN] no db path given, must recurse if enabled');
recurse();

View File

@ -13,17 +13,19 @@ module.exports.create = function (cli, engine, dnsd) {
res.send({ nameservers: [] });
});
app.get('/api/zones', function (req, res) {
engine.zones.all(function (zones) {
engine.zones.all(function (err, zones) {
res.send({ zones: zones });
});
});
app.get('/api/records/:zone', function (req, res) {
engine.records.all(function (records) {
engine.records.all(function (err, records) {
res.send({ records: records });
});
});
httpServer.listen(cli.http);
httpServer.listen(cli.http, function () {
console.log(httpServer.address().address + '#' + httpServer.address().port + ' (http)');
});
}
runHttp();

3
lib/public/index.html Normal file
View File

@ -0,0 +1,3 @@
<p><a href="/api/peers">/api/peers</p>
<p><a href="/api/zones">/api/zones</p>
<p><a href="/api/records">/api/records/:zone</p>

View File

@ -8,7 +8,7 @@ module.exports.create = function (opts) {
engine.primaryNameservers = db.primaryNameservers;
engine.zones = {
all: function (query, cb) {
all: function (cb) {
process.nextTick(function () {
cb(null, db.domains.slice(0));
});
@ -23,7 +23,7 @@ module.exports.create = function (opts) {
}
};
engine.records = {
all: function (query, cb) {
all: function (cb) {
process.nextTick(function () {
cb(null, db.records.slice(0));
});

View File

@ -61,7 +61,7 @@ module.exports.create = function (cli, dnsd) {
});
tcpServer.listen(cli.port, function () {
console.log('TCP Server bound');
console.log(tcpServer.address().address + '#' + tcpServer.address().port + ' (tcp)');
});
return tcpServer;