digd.js/lib/httpd.js

34 lines
891 B
JavaScript

'use strict';
module.exports.create = function (cli, engine, dnsd) {
function runHttp() {
var path = require('path');
var express = require('express');
var app = express();
var httpServer = require('http').createServer(app);
app.use('/', express.static(path.join(__dirname, 'public')));
app.get('/api/peers', function (req, res) {
res.send({ nameservers: [] });
});
app.get('/api/zones', function (req, res) {
engine.zones.all(function (err, zones) {
res.send({ zones: zones });
});
});
app.get('/api/records/:zone', function (req, res) {
engine.records.all(function (err, records) {
res.send({ records: records });
});
});
httpServer.listen(cli.http, function () {
console.log(httpServer.address().address + '#' + httpServer.address().port + ' (http)');
});
}
runHttp();
};