-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
143 lines (111 loc) · 4.18 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//-------------importes------------
const express = require('express')
const fs = require('fs');
const bodyParser = require('body-parser');
const session = require('express-session')
const path = require('path');
const nodemailer = require('nodemailer')
const ejs = require('ejs')
const ytdl = require(`ytdl-core`)
//------------Configs--------------
const app = express();
require('dotenv').config()
app.use(session({
secret: process.env.SECRET || '35515153135gses',
resave: false,
saveUninitialized: true,
}))
const SMTP_CONFIG = require('./config/smtp');
const trasporter = nodemailer.createTransport({
host: SMTP_CONFIG.host,
port: SMTP_CONFIG.port,
service:'gmail',
secure: true,
auth:{
user: SMTP_CONFIG.user,
pass: SMTP_CONFIG.pass
},
tls:{
rejectUnauthorized: false
}
})
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json())
app.use(express.static('views'));
app.use(express.static('public'));
app.use(express.static('uploads'));
app.use('/uploads', express.static(path.join(__dirname, '/uploads')));
app.use('/public', express.static(path.join(__dirname, '/public')));
app.set('views', './views')
app.set('view engine', 'ejs');
//----------------POST--------------------
app.post('/contact/menssage', (req,res)=>{
let data = {
nome: req.body.nome,
email: req.body.email,
mensagem: req.body.message,
lang: req.body.lang,
color: req.body.color
}
if (data.lang == 'pt-BR') {
trasporter.sendMail({
text: 'Olá sua mensagem já foi recebida logo entrarei em contato.',
html:`<b>Olá sua mensagem já foi recebida logo entrarei em contato.</b><br><br><a href="https://fernandojunio.com.br"><button style="padding: 10px; background-color: ${data.color}; color: white; font-weight: bold; outline: none; border: 1px solid #c4c4c488; cursor:pointer;">Ir para o Portfólio</button></a>`,
subject: "Nova Mensagem de Fernando Júnio",
from: "Fernando Júnio <[email protected]>",
to: [data.email,'[email protected]']
})
}else if(data.lang == 'en-US'){
trasporter.sendMail({
text: 'Hello, your message has been received, I will contact you soon.',
html:`<b>Hello, your message has been received, I will contact you soon.</b><br><br><a href="https://fernandojunio.com.br"><button style="padding: 10px; background-color: ${data.color}; color: white; font-weight: bold; outline: none; border: 1px solid #c4c4c488; cursor:pointer;">Ir para o Portfólio</button></a>`,
subject: "New Message from Fernando Júnio",
from: "Fernando Júnio <[email protected]>",
to: [data.email,'[email protected]']
})
}
trasporter.sendMail({
text: data.nome +" | "+ data.email +" | "+ data.mensagem,
html: '<b>Nome: </b>' + data.nome +" <br><br> "+ '<b>Email: </b>' +data.email +" <br><br> "+ '<b>Mensagem: </b>' +data.mensagem,
subject: "Nova Mensagem do Portifolio enviada por "+ data.nome,
from: "Fernando Júnio <[email protected]>",
to: ['[email protected]','[email protected]']
})
res.status(200).json({
success:true
})
})
//-----------------GET--------------------
app.get('/',(req,res)=>{
res.render('index')
})
app.get('/about',(req, res)=>{
res.render('about')
})
app.get('/skills',(req, res)=>{
res.render('skills')
})
app.get('/work',(req, res)=>{
res.render('work')
})
app.get('/contact',(req, res)=>{
res.render('contact')
})
app.get('/curriculo',(req, res)=>{
res.render('curriculo')
})
app.get('/curriculo/certificados',(req,res)=>{
res.render('certificados')
})
app.post(`/downloadExtension/getLink`,async(req,res)=>{
if (req.body.ytlink) {
const info = await ytdl.getInfo(req.body.ytlink)
const link = ytdl.chooseFormat(info.formats, { filter: 'audioonly' }).url
res.status(200).send({link:link})
}
})
//----------------SERVER-------------------
const port = process.env.PORT_APP || 3131
app.listen(port,()=>{
console.log(`Servidor rodando na porta ${port}` );
});