From 77e3096cd314c588c9a73489610f2485b6e75afa Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 24 Jan 2018 03:06:32 -0700 Subject: [PATCH] update existing records --- lib/httpd.js | 30 +++++++++++++++++------------- lib/public/js/app.js | 5 ++++- package.json | 1 + 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/httpd.js b/lib/httpd.js index f922391..11a05cb 100644 --- a/lib/httpd.js +++ b/lib/httpd.js @@ -32,11 +32,15 @@ module.exports.create = function (cli, engine/*, dnsd*/) { jwt = require('jsonwebtoken'); privpem = require('jwk-to-pem')(jwk, { private: true }); pubpem = require('jwk-to-pem')(jwk, { private: false }); - console.log(privpem); - console.log("================================"); - console.log(" JWT Write Authorization Token: "); - console.log("================================"); - console.log(jwt.sign( + console.info("===================="); + console.info(" EC256 Private PEM: "); + console.info("===================="); + console.info(privpem); + console.info(); + console.info("================================"); + console.info(" JWT Write Authorization Token: "); + console.info("================================"); + console.info(jwt.sign( { sub: subparts[0] , iss: subparts[1] , aud: 'localhost' @@ -65,10 +69,10 @@ module.exports.create = function (cli, engine/*, dnsd*/) { message: 'jwt not active', date: +050046-12-28T01:12:58.000Z } */ - console.log("==============================="); - console.log(" JWT Read Authorization Token: "); - console.log("==============================="); - console.log(jwt.sign( + console.info("==============================="); + console.info(" JWT Read Authorization Token: "); + console.info("==============================="); + console.info(jwt.sign( { sub: subparts[0] , iss: subparts[1] , aud: 'localhost' @@ -79,12 +83,13 @@ module.exports.create = function (cli, engine/*, dnsd*/) { , algorithm: 'ES256' } )); - console.log("=========================="); + console.info("=========================="); } function runHttp() { var path = require('path'); var express = require('express'); + var jsonParser = require('body-parser').json({ strict: true, limit: '100kb' }); var app = express(); var httpServer = require('http').createServer(app); @@ -240,8 +245,7 @@ module.exports.create = function (cli, engine/*, dnsd*/) { }).map(mapRecord) }); }); }); - app.post('/api/records/:id?', hasClaim('+rw@adns.org'), function (req, res) { - console.log('req.body:', req.body); + app.post('/api/records/:id?', jsonParser, hasClaim('+rw@adns.org'), function (req, res) { var record = req.body || {}; record.id = req.params.id || record.id; @@ -260,7 +264,7 @@ module.exports.create = function (cli, engine/*, dnsd*/) { app.use('/', express.static(path.join(__dirname, 'public'))); httpServer.listen(cli.http, function () { - console.log(httpServer.address().address + '#' + httpServer.address().port + ' (http)'); + console.info(httpServer.address().address + '#' + httpServer.address().port + ' (http)'); }); } diff --git a/lib/public/js/app.js b/lib/public/js/app.js index 98fa2e4..5d24b4d 100644 --- a/lib/public/js/app.js +++ b/lib/public/js/app.js @@ -332,7 +332,10 @@ return window.fetch( '/api/records/' + record.id , { method: 'POST' - , headers: new window.Headers({ 'Authorization': 'Bearer ' + auth }) + , headers: new window.Headers({ + 'Authorization': 'Bearer ' + auth + , 'Content-Type': 'application/json;charset=UTF-8' + }) , body: JSON.stringify(record) } ).then(function (resp) { diff --git a/package.json b/package.json index c5856bd..976480b 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "author": "AJ ONeal (https://coolaj86.com)", "license": "MIT OR Apache-2.0", "dependencies": { + "body-parser": "^1.18.2", "dig.js": "git+https://git.coolaj86.com/coolaj86/dig.js#v1.3", "express": "^4.16.2", "hexdump.js": "git+https://git.coolaj86.com/coolaj86/hexdump.js#v1.0.4",