-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (31 loc) · 1.01 KB
/
server.js
File metadata and controls
36 lines (31 loc) · 1.01 KB
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
const express = require('express');
const sendMail = require('./mail');
const log = console.log;
const app = express();
const cors = require('cors');
const path = require('path');
const PORT = process.env.PORT || 3000;
// Configuring our data parsing
app.use(express.urlencoded({
extend: false
}));
app.use(express.json());
app.use(cors());
app.post('/email', (req, res) => {
// res.sendFile(path.join(__dirname + '/contact-us.html'));
//send email here
const { name, subject, email, text } = req.body;
console.log('Data: ', req.body);
sendMail(name, email, subject, text, function(err, data) {
if (err) {
res.status(500).json({ message: err });
} else {
res.status(200).json({ message: 'Email sent successfully!' });
}
});
});
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, 'views', 'index.html'));
//__dirname : It will resolve to your project folder.
});
app.listen(PORT, () => log('Server is starting on PORT,', 8080));