forked from aledbf/EmailValidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (66 loc) · 1.88 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var q = require('q');
var externalAddressController = require('./controllers/externalAddressController');
var emailValidatorController = require('./controllers/validatorController');
var helo = '';
var EmailValidator = {
/**
* checks an email address for validity.
* @param email string
* @param options " {externalIpAddress: string, redisPort: integer, redisHost: string} "
* @param callback function(failure, success)
*/
checkEmailAddress: function(email, options, callback) {
emailValidatorController.checkEmailAddress(email, options).then(function(data) {
callback(null, data);
}, function(error) {
callback(error, null);
});
},
/**
* gets the external IP address from a 3rd party api
* @param callback function(failure, success)
*/
getExternalIp: function(callback) {
if (helo) {
callback(null, helo);
} else {
externalAddressController.getAddress().then(function(data) {
callback(null, data);
}, function(error) {
callback(error, null);
});
}
},
/**
* starts the web server with the options specified.
* {
* port: integer,
* externalIpAddress: string,
* redisPort: integer,
* redisHost: string
* }
* @param options
* @param callback
*/
startWebServer: function(options, callback) {
require('./controllers/webServerController')(options);
}
};
module.exports = EmailValidator;
// start the web server automatically if the startWebServer parameter is passed
if (process.argv.length >= 3 && process.argv[2] === 'startWebServer') {
var options = {
redisPort: 6379,
port: 3000
};
if (process.argv.length >= 4) {
options.redisPort = process.argv[3];
}
if (process.argv.length >= 5) {
options.port = process.argv[4];
}
if (process.argv.length >= 6) {
helo = process.argv[5];
}
EmailValidator.startWebServer(options);
}