From 9ffb9e334c822a03a2de216bf264eb622ad4a852 Mon Sep 17 00:00:00 2001 From: Renge Date: Wed, 17 Apr 2024 18:40:52 -0400 Subject: [PATCH] fix: repeated result when resubmit --- Project/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Project/index.js b/Project/index.js index dc09e13..397694f 100644 --- a/Project/index.js +++ b/Project/index.js @@ -4,10 +4,6 @@ const swipl = require('swipl'); const app = express() const PORT = 3000 -swipl.call('assert(ip("_", "_"))'); -swipl.call('assert(nip("_", "_"))'); -swipl.call('assert(all("_", "_"))'); -swipl.call('assert((allowed_to_send_email(Domain, IP) :- (ip(Domain, IP)), once(\\+ all(Domain, "-"); \\+ nip(Domain, IP))))'); const spf = (req, res) => { try { @@ -40,6 +36,10 @@ const spf = (req, res) => { console.error(err) return res.status(err.code).send(err.message) } + swipl.call('assert(ip("_", "_"))'); + swipl.call('assert(nip("_", "_"))'); + swipl.call('assert(all("_", "_"))'); + swipl.call('assert((allowed_to_send_email(Domain, IP) :- (ip(Domain, IP)), once(\\+ all(Domain, "-"); \\+ nip(Domain, IP))))'); const query = new swipl.Query(`allowed_to_send_email(${domain}, IP)`); let ret = null; let result = [] @@ -48,6 +48,8 @@ const spf = (req, res) => { result.push(`${ret.IP}`); } query.close(); + swipl.cleanup() + swipl.initialise() return res.status(200).send(result) }) })