From 45800a42ec01f3cf174c890396ed809f82a20632 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 3 May 2019 00:01:06 -0600 Subject: [PATCH] dns and http relay with api check --- package-lock.json | 6 ++++++ package.json | 1 + server.js | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2060678..7eaa7b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,12 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@root/request": { + "version": "1.3.10", + "resolved": "https://registry.npmjs.org/@root/request/-/request-1.3.10.tgz", + "integrity": "sha512-GSn8dfsGp0juJyXS9k7B/DjYm7Axe85wiCHfPs30eQ+/V6p2aqey45e1czb3ZwP+iPmzWCKXahhWnZhSDIil6w==", + "dev": true + }, "accepts": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.6.tgz", diff --git a/package.json b/package.json index a29af32..e122eeb 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "author": "AJ ONeal (https://coolaj86.com/)", "license": "MPL-2.0", "devDependencies": { + "@root/request": "^1.3.10", "dig.js": "^1.3.9", "dns-suite": "^1.2.12", "express": "^4.16.4" diff --git a/server.js b/server.js index 33e6e40..553ab31 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,7 @@ var crypto = require('crypto'); //var dnsjs = require('dns-suite'); var dig = require('dig.js/dns-request'); +var request = require('util').promisify(require('@root/request')); var express = require('express'); var app = express(); @@ -13,7 +14,6 @@ var nameserver = nameservers[index]; app.use('/', express.static('./')); app.use('/api', express.json()); app.get('/api/dns/:domain', function (req, res, next) { - console.log(req.params); var domain = req.params.domain; var casedDomain = domain.toLowerCase().split('').map(function (ch) { // dns0x20 takes advantage of the fact that the binary operation for toUpperCase is @@ -117,12 +117,23 @@ app.get('/api/dns/:domain', function (req, res, next) { dig.resolveJson(query, opts); }); +app.get('/api/http', function (req, res) { + var url = req.query.url; + return request({ method: 'GET', url: url }).then(function (resp) { + res.send(resp.body); + }); +}); +app.get('/api/_acme_api_', function (req, res) { + res.send({ success: true }); +}); module.exports = app; if (require.main === module) { // curl -L http://localhost:3000/api/dns/example.com?type=A - console.log("Listening on localhost:3000"); + console.info("Listening on localhost:3000"); app.listen(3000); - console.log("Try this:"); - console.log("\tcurl -L 'http://localhost:3000/api/dns/example.com?type=A'"); + console.info("Try this:"); + console.info("\tcurl -L 'http://localhost:3000/api/_acme_api_/'"); + console.info("\tcurl -L 'http://localhost:3000/api/dns/example.com?type=A'"); + console.info("\tcurl -L 'http://localhost:3000/api/http/?url=https://example.com'"); }