diff --git a/Project/index.js b/Project/index.js index c83136f..533b623 100644 --- a/Project/index.js +++ b/Project/index.js @@ -1,19 +1,21 @@ const express = require('express') const dns = require('dns'); const swipl = require('swipl'); +const path = require('path'); const app = express() const PORT = 3000 const spf = (req, res) => { try { + res.setHeader('Content-Type', 'application/json'); const { domain } = req.query; console.log(domain) let spf = "" dns.resolveTxt(domain, (err, address) => { if (err) { console.error("ERROR", err) - return res.status(400).send("ERROR: occur on resolving SPF") + return res.status(400).json("ERROR: occur on resolving SPF") } else { console.log(address) @@ -28,14 +30,14 @@ const spf = (req, res) => { } if (!spf) { console.error("ERROR: not spf") - return res.status(400).send(`ERROR: No SPF record found in ${domain}`) + return res.status(400).json(`ERROR: No SPF record found in ${domain}`) } const spfArray = spf.split(" "); console.log(spfArray) return parseSPF(domain, spfArray, swipl, domain, (err) => { if (err) { console.error("ERROR", err) - return res.status(err.code).send(err.message) + return res.status(err.code).json(err.message) } else { swipl.call('assert(ip4("_", "_"))'); @@ -63,7 +65,7 @@ const spf = (req, res) => { query.close(); swipl.cleanup() swipl.initialise() - return res.status(200).send({spf: spf, allowedIP4: [...new Set(allowedIP4)], allowedIP6: [...new Set(allowedIP6)]}) + return res.status(200).json({spf: spf, allowedIP4: [...new Set(allowedIP4)], allowedIP6: [...new Set(allowedIP6)]}) } }) }) @@ -75,15 +77,16 @@ const spf = (req, res) => { const a = (req, res) => { try { + res.setHeader('Content-Type', 'application/json'); const { domain } = req.query; console.log(domain) dns.resolve4(domain, (err, address) => { if (err) { console.log(err) - return res.status(400).send("ERROR: No a record found") + return res.status(400).json("ERROR: No a record found") } else { - return res.status(200).send(address) + return res.status(200).json(address) } }) } @@ -94,15 +97,16 @@ const a = (req, res) => { const mx = (req, res) => { try { + res.setHeader('Content-Type', 'application/json'); const { domain } = req.query; console.log(domain) dns.resolveMx(domain, (err, address) => { if (err) { console.log(err) - return res.status(400).send("ERROR: No mx record found") + return res.status(400).json("ERROR: No mx record found") } else { - return res.status(200).send(address) + return res.status(200).json(address) } }) } @@ -329,6 +333,7 @@ const parseSPF = (domain, spf, swipl, curr, callback) => { app.get('/spf', spf) app.get('/a', a) app.get('/mx', mx) +app.use(express.static(path.join(__dirname, 'public'))); app.listen(PORT, (err) => { if (err) { diff --git a/Project/public/index.html b/Project/public/index.html new file mode 100644 index 0000000..a3c8f2c --- /dev/null +++ b/Project/public/index.html @@ -0,0 +1,42 @@ + + + + + + + + + + + +

Results:

+
a:
+

+    
mx:
+

+    
spf:
+

+
+    
+
+