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');
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)');
});
}

View File

@ -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) {

View File

@ -47,6 +47,7 @@
"author": "AJ ONeal <coolaj86@gmail.com> (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",