From c581cd642440a5ac077f5073f6fbe3920b729ba7 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Mon, 10 Jun 2024 18:02:33 +0300 Subject: Refactoring --- api/routes/getPeers/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'api/routes/getPeers') diff --git a/api/routes/getPeers/index.js b/api/routes/getPeers/index.js index 22da56e..b18a015 100644 --- a/api/routes/getPeers/index.js +++ b/api/routes/getPeers/index.js @@ -4,8 +4,10 @@ const fs = require('fs'); module.exports = (req, res) => { const path = config.peersFile; if(fs.existsSync(path)){ - res.send(JSON.parse(fs.readFileSync(path))); + res.writeHead(200, {'Content-Type': 'application/json'}); + res.end(JSON.stringify(JSON.parse(fs.readFileSync(path)))); } else { - res.send({"error":"404"}) + res.writeHead(404, {'Content-Type': 'application/json'}); + res.end({"error":"No peers :("}) } }; -- cgit v1.2.3