-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (58 loc) · 2.03 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
74
75
76
77
require('dotenv-defaults').config()
const express = require('express')
const path = require('path')
const cors = require('cors')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
// ========= Apollo(GraphQL) ======
const { ApolloServer } = require('apollo-server-express')
const { typeDefs } = require('./server/schema')
const { resolvers } = require('./server/resolvers')
// ========= Apollo(GraphQL) ======
// =========require mailer ==========
const mailer = require('./server/mailer/mailer.js')
const User = require('./server/models/users')
const Template = require('./server/models/templates')
const Sent = require('./server/models/sents')
const playground = true
const server = new ApolloServer({ typeDefs, resolvers, playground })
const app = express()
server.applyMiddleware({ app })
app.use(cors())
app.use(express.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(express.static(path.join(__dirname, 'client/dist')))
app.post('/sendMails', (req, res) => {
const { userinfo, subject, to, html } = req.body
const { emailAddress, emailPassword } = userinfo
const transporterConfig = {
host: 'smtp.gmail.com',
user: emailAddress,
pass: emailPassword,
}
const mailOption = {
from: emailPassword,
to: to,
subject: subject,
html: html,
}
let mailer1 = new mailer(transporterConfig, mailOption)
mailer1.sendMail(res)
})
app.get('*', (req, res, next) => {
res.sendFile(path.join(__dirname + '/client/dist/index.html'))
})
// //===========================Login DB==================================
// DB Config
// const db = require('./server/config/keys').MongoURI
// DB Connection
if (!process.env.MONGO_URL) {
console.error('Missing MONGO_URL!!!')
process.exit(1)
}
mongoose
.connect(process.env.MONGO_URL, { useNewUrlParser: true })
.then(() => console.log('Mongo Connected! Path:', process.env.ROOTPATH))
.catch((err) => console.log(err))
const port = process.env.PORT || 5000
app.listen(port)