forked from ryanbolton92/email-finder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (41 loc) · 1.3 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
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser')
var debug = require('debug')('index');
var emailFinder = require('./lib/email-finder');
var app = express();
process.env.NODE_ENV = process.env.NODE_ENV || 'dev';
var rootDir = path.resolve(__dirname);
app.set('port', (process.env.PORT || 5000));
// Configure jade as template engine
app.set('views', rootDir + '/views');
app.set('view engine', 'ejs');
app.set("view options", {layout: false});
// Parse the body
// Warning: http://andrewkelley.me/post/do-not-use-bodyparser-with-express-js.html
// parse application/json
app.use(bodyParser.json())
// Serve static content from "public" directory
app.use(express.static(rootDir + '/public'));
app.get('/', function(req, res){
res.render('index', {
GOOGLE_ANALYTICS_ID: process.env.GOOGLE_ANALYTICS_ID || ''
});
});
app.post('/find', function(req, res) {
var data = {
name: req.body.first_name + ' ' + req.body.last_name,
domain: req.body.domain
};
emailFinder(data)
.then(function (email) {
res.send({email: email});
})
.catch(function (err) {
res.status(500).send(err);
})
});
// All set, start listening!
app.listen(app.get('port'), function() {
console.log(`Server running at http://localhost:${app.get('port')}`);
});