-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
executable file
·62 lines (54 loc) · 1.66 KB
/
server.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
const dotenv = require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const nodemailer = require("nodemailer");
const CONFIG = require('./config.json');
const mailConfig = require('./env.json');
const fs = require('fs');
const connection = mongoose.connect(CONFIG.MONGO_URL);
const app = require('./app');
const path = require('path');
app.use('/', express.static(path.join(__dirname, 'public')));
mongoose.connection.once('open', function() {
console.log('connected');
var server = app.listen(13001, function(){
var host = server.address().address;
var port = server.address().port;
console.log('listening on',host, port);
});
});
/*------------------SMTP Start-----------------------------*/
var smtpTransport = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
auth: {
user: mailConfig.SMTP_LOGIN,
pass: mailConfig.SMTP_PASSW
}
});
/*------------------SMTP Over-----------------------------*/
/*------------------Routing Started ------------------------*/
app.get('/',function(req,res){
res.sendfile('Map.js');
});
app.get('/send',function(req,res){
var mailOptions={
from: "PollerBears <[email protected]",
to : req.query.to,
subject : req.query.subject,
text : req.query.text
}
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
res.end("error");
}else{
console.log("Message sent: " + response.message);
res.end("sent");
}
});
});
app.listen(18000,function(){
console.log("Express Started on Port 18000");
});