Sign up basic blacklisting

node v8.17.0
version: 15.0.0
endpointsharetweet
Find known lists of disposable and free email domains and create function to check any email towards this list.
const request = require('superagent') let str = ''; const disp = await request.get('https://raw.githubusercontent.com/martenson/disposable-email-domains/master/disposable_email_blacklist.conf') const free = await request.get('https://gist.githubusercontent.com/tbrianjones/5992856/raw/87f527af7bdd21997722fa65143a9af7bee92583/free_email_provider_domains.txt') str += disp.res.text; str += free.res.text; str;
// List of domains to blacklist 'Blacklist domains → ' + str.split('\n').length + ' domains';
Add function to find domain of email and check if domain should be blocked
// Tests const findTestablePartOfEmail = (email)=>{ return email.split('@')[1]; } const shouldEmailBeBlocked = (email)=>{ if(str.match(findTestablePartOfEmail(email))){ return true; } return false; }
Testing the functionality
// Should return true shouldEmailBeBlocked('anything@gmail.com');
shouldEmailBeBlocked('anything@mail.ru');
shouldEmailBeBlocked('anything@mail.ru');
// Should return false shouldEmailBeBlocked('anything@gelato.com')
Adding API Endpoint for checking email towards blacklist Ex: POST {"email": "anything@gmail.com"} https://sign-up-basic-blacklisting-2yqzen4wif2w.runkit.sh/check-email
const express = require("@runkit/runkit/express-endpoint/1.0.0"); const bodyParser = require('body-parser'); const app = express(exports); app.use(bodyParser.json()); // JSON response app.post("/check-email", (req, res) => res.send({ "email": req.body.email, "domain": findTestablePartOfEmail(req.body.email), "isGenericEmail" : shouldEmailBeBlocked(req.body.email) })); // JSON P Support app.post("/check-email/:execute", (req, res) => res.send(req.params.execute +'('+ JSON.stringify({ "email": req.body.email, "domain": findTestablePartOfEmail(req.body.email), "isGenericEmail" : shouldEmailBeBlocked(req.body.email) })+')')); app.get('/', (req,res)=> res.send({ "services": { "/check-email" : { "method": "POST", "variables": { "email": "string" } } } }));
Testing the API
var test = await request.post('https://sign-up-basic-blacklisting-2yqzen4wif2w.runkit.sh/check-email').send({email: "eivind@gelato.com"}) test.res.text;
Loading…

no comments

    sign in to comment