Skip to content
Snippets Groups Projects
Commit b20ea938 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

nameservice: set response content-type to json

Change-Id: I00a67f4a7b7c1186464df7d24640e97f9390e911
parent 639e2315
Branches
No related tags found
No related merge requests found
...@@ -133,6 +133,7 @@ function startServer() { ...@@ -133,6 +133,7 @@ function startServer() {
app.disable('x-powered-by'); app.disable('x-powered-by');
app.use(bodyParser.json()); app.use(bodyParser.json());
app.get("/name/:name", function(req, http_res) { app.get("/name/:name", function(req, http_res) {
http_res.setHeader('Content-Type', 'application/json');
reg.addr(req.params.name, function(err, res) { reg.addr(req.params.name, function(err, res) {
if (isHashZero(res)) { if (isHashZero(res)) {
http_res.status(404).end(JSON.stringify({"error": "name not registred"})); http_res.status(404).end(JSON.stringify({"error": "name not registred"}));
...@@ -142,6 +143,7 @@ function startServer() { ...@@ -142,6 +143,7 @@ function startServer() {
}); });
}); });
app.get("/name/:name/owner", function(req, http_res) { app.get("/name/:name/owner", function(req, http_res) {
http_res.setHeader('Content-Type', 'application/json');
reg.owner(req.params.name, function(err, res) { reg.owner(req.params.name, function(err, res) {
if (isHashZero(res)) { if (isHashZero(res)) {
http_res.status(404).end(JSON.stringify({"error": "name not registred"})); http_res.status(404).end(JSON.stringify({"error": "name not registred"}));
...@@ -152,6 +154,7 @@ function startServer() { ...@@ -152,6 +154,7 @@ function startServer() {
}); });
}); });
app.get("/addr/:addr", function(req, http_res) { app.get("/addr/:addr", function(req, http_res) {
http_res.setHeader('Content-Type', 'application/json');
var addr = formatAddress(req.params.addr); var addr = formatAddress(req.params.addr);
if (!addr) { if (!addr) {
console.log("Error parsing input address"); console.log("Error parsing input address");
...@@ -161,12 +164,13 @@ function startServer() { ...@@ -161,12 +164,13 @@ function startServer() {
reg.name(addr, function(err, res) { reg.name(addr, function(err, res) {
var name = parseString(res); var name = parseString(res);
if (name) if (name)
http_res.end(JSON.stringify({"name": parseString(res)})); http_res.end(JSON.stringify({"name": name}));
else else
http_res.status(404).end(JSON.stringify({"error": "address not registred"})); http_res.status(404).end(JSON.stringify({"error": "address not registred"}));
}); });
}); });
app.post("/name/:name", function(req, http_res) { app.post("/name/:name", function(req, http_res) {
http_res.setHeader('Content-Type', 'application/json');
var addr = formatAddress(req.body.addr); var addr = formatAddress(req.body.addr);
if (!addr) { if (!addr) {
console.log("Error parsing input address"); console.log("Error parsing input address");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment