aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/routes/announceZChain/index.js6
-rw-r--r--api/routes/getInnerIPFSContent/index.js15
2 files changed, 14 insertions, 7 deletions
diff --git a/api/routes/announceZChain/index.js b/api/routes/announceZChain/index.js
index a1b336c..0261aa4 100644
--- a/api/routes/announceZChain/index.js
+++ b/api/routes/announceZChain/index.js
@@ -22,9 +22,11 @@ module.exports = (req, res) => {
if (regex.test(zchain)){
getNSvalidity(zchain,res);
} else {
- res.send({error:"Invalid data"});
+ res.writeHead(404, { 'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"Invalid data"}));
}
} else {
- res.send({error:"Invalid data"});
+ res.writeHead(404, { 'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"Invalid data"}));
}
}
diff --git a/api/routes/getInnerIPFSContent/index.js b/api/routes/getInnerIPFSContent/index.js
index b3a05cb..721e836 100644
--- a/api/routes/getInnerIPFSContent/index.js
+++ b/api/routes/getInnerIPFSContent/index.js
@@ -1,4 +1,3 @@
-const { spawn } = require('child_process');
const fs = require("fs");
const config = require("../../config");
@@ -11,8 +10,11 @@ const config = require("../../config");
*
*/
function fetchZblock(zblock, res){
- res.send(fs.readFileSync(config.workDir+"/ipfs/"+zblock));
+ res.writeHead(200, { 'Content-Type': 'application/json'});
+ var path = config.workDir+"/ipfs/"+zblock;
+ res.end(JSON.stringify(JSON.parse(fs.readFileSync(path))));
};
+
module.exports = (req, res) => {
console.log(req.query)
if ( (req.query.ipfs) && typeof req.query.ipfs === "string" && req.query.ipfs.length === 46 ){
@@ -20,14 +22,17 @@ module.exports = (req, res) => {
regex= /Qm[A-Za-z0-9]{44}/;
if (regex.test(ipfs)){
if (ipfs === "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH" ){
- res.send({error:"Genesis block"});
+ res.writeHead(200, { 'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"Genesis block"}));
} else {
fetchZblock(ipfs,res);
}
} else {
- res.send({error:"Invalid data: regexp failed to pass"});
+ res.writeHead(404, { 'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"Invalid data: regexp failed to pass"}));
}
} else {
- res.send({error:"Invalid data: no valid zblock was provided"});
+ res.writeHead(404, { 'Content-Type': 'application/json'});
+ res.end(JSON.stringify({error:"Invalid data: no valid zblock was provided"}));
}
}