-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
83 lines (65 loc) · 2.29 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const {createServer} = require('http');
const express = require('express');
// const bodyParser = require('body-parser');
const compression = require('compression');
const morgan = require('morgan');
const path = require('path');
// const nodemailer = require('nodemailer');
const app = express();
const normalizePort = port => parseInt(port, 10);
const PORT = normalizePort(process.env.PORT || 5000);
const dev = app.get('env') !== 'production';
if (!dev) {
app.disable('x-powered-by');
app.use(compression());
app.use(morgan('common'));
app.use(express.static(path.resolve(__dirname,'build')));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'build', 'index.html'));
});
}
if (dev) {
app.use(morgan('dev'));
}
const server = createServer(app);
server.listen(PORT, err => {
if (err) throw err;
console.log(`server started at port ${PORT}`);
});
// // body parser middleware
// app.use(bodyParser.urlencoded({ extended: false}));
// app.use(bodyParser.json());
// app.post('/api/form', (req, res) => {
// console.log(req.body)
// });
// // STTIC FOLDER
// // app.use('/public', express.static(path.join(__dirname,'public')));
// const PORT = process.env.PORT || 3001
// app.listen(PORT, () => {
// console.log(`Server started on port ${PORT}`);
// });
// const transporter = nodemailer.createTransport({
// host: 'smtp.ethereal.email',
// port: 587,
// auth: {
// user: '[email protected]',
// pass: 'XT9mxquDTVCSPJDDFb'
// }
// });
// let mailOptions = {
// from: '"Fred Foo 👻" <[email protected]>', // sender address
// to: '[email protected]', // list of receivers
// subject: 'Hello ✔', // Subject line
// text: 'Hello world?', // plain text body
// html: '<br>Hello world? twice?</br>' // html body
// };
// transporter.sendMail(mailOptions, (error, info) => {
// if (error) {
// return console.log(error);
// }
// console.log('Message sent: %s', info.messageId);
// // Preview only available when sending through an Ethereal account
// console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// // Message sent: <[email protected]>
// // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
// });