update existing records

This commit is contained in:
AJ ONeal 2018-01-24 03:06:32 -07:00
parent d586e011e2
commit 77e3096cd3
3 changed files with 22 additions and 14 deletions

View File

@ -32,11 +32,15 @@ module.exports.create = function (cli, engine/*, dnsd*/) {
jwt = require('jsonwebtoken'); jwt = require('jsonwebtoken');
privpem = require('jwk-to-pem')(jwk, { private: true }); privpem = require('jwk-to-pem')(jwk, { private: true });
pubpem = require('jwk-to-pem')(jwk, { private: false }); pubpem = require('jwk-to-pem')(jwk, { private: false });
console.log(privpem); console.info("====================");
console.log("================================"); console.info(" EC256 Private PEM: ");
console.log(" JWT Write Authorization Token: "); console.info("====================");
console.log("================================"); console.info(privpem);
console.log(jwt.sign( console.info();
console.info("================================");
console.info(" JWT Write Authorization Token: ");
console.info("================================");
console.info(jwt.sign(
{ sub: subparts[0] { sub: subparts[0]
, iss: subparts[1] , iss: subparts[1]
, aud: 'localhost' , aud: 'localhost'
@ -65,10 +69,10 @@ module.exports.create = function (cli, engine/*, dnsd*/) {
message: 'jwt not active', message: 'jwt not active',
date: +050046-12-28T01:12:58.000Z } date: +050046-12-28T01:12:58.000Z }
*/ */
console.log("==============================="); console.info("===============================");
console.log(" JWT Read Authorization Token: "); console.info(" JWT Read Authorization Token: ");
console.log("==============================="); console.info("===============================");
console.log(jwt.sign( console.info(jwt.sign(
{ sub: subparts[0] { sub: subparts[0]
, iss: subparts[1] , iss: subparts[1]
, aud: 'localhost' , aud: 'localhost'
@ -79,12 +83,13 @@ module.exports.create = function (cli, engine/*, dnsd*/) {
, algorithm: 'ES256' , algorithm: 'ES256'
} }
)); ));
console.log("=========================="); console.info("==========================");
} }
function runHttp() { function runHttp() {
var path = require('path'); var path = require('path');
var express = require('express'); var express = require('express');
var jsonParser = require('body-parser').json({ strict: true, limit: '100kb' });
var app = express(); var app = express();
var httpServer = require('http').createServer(app); var httpServer = require('http').createServer(app);
@ -240,8 +245,7 @@ module.exports.create = function (cli, engine/*, dnsd*/) {
}).map(mapRecord) }); }).map(mapRecord) });
}); });
}); });
app.post('/api/records/:id?', hasClaim('+rw@adns.org'), function (req, res) { app.post('/api/records/:id?', jsonParser, hasClaim('+rw@adns.org'), function (req, res) {
console.log('req.body:', req.body);
var record = req.body || {}; var record = req.body || {};
record.id = req.params.id || record.id; 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'))); app.use('/', express.static(path.join(__dirname, 'public')));
httpServer.listen(cli.http, function () { httpServer.listen(cli.http, function () {
console.log(httpServer.address().address + '#' + httpServer.address().port + ' (http)'); console.info(httpServer.address().address + '#' + httpServer.address().port + ' (http)');
}); });
} }

View File

@ -332,7 +332,10 @@
return window.fetch( return window.fetch(
'/api/records/' + record.id '/api/records/' + record.id
, { method: 'POST' , { 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) , body: JSON.stringify(record)
} }
).then(function (resp) { ).then(function (resp) {

View File

@ -47,6 +47,7 @@
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)", "author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)",
"license": "MIT OR Apache-2.0", "license": "MIT OR Apache-2.0",
"dependencies": { "dependencies": {
"body-parser": "^1.18.2",
"dig.js": "git+https://git.coolaj86.com/coolaj86/dig.js#v1.3", "dig.js": "git+https://git.coolaj86.com/coolaj86/dig.js#v1.3",
"express": "^4.16.2", "express": "^4.16.2",
"hexdump.js": "git+https://git.coolaj86.com/coolaj86/hexdump.js#v1.0.4", "hexdump.js": "git+https://git.coolaj86.com/coolaj86/hexdump.js#v1.0.4",