Guest User

Untitled

a guest
May 23rd, 2018
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. export default () => (
  2. <div className="contact">
  3. <div className="contact__form">
  4. <form method="post" action="/contact">
  5. <input name="firstName" field="firstName" placeholder='Name' />
  6. <input name="e-mail" field="e-mail" placeholder='E-mail' />
  7. <input name="subject" field="subject" placeholder='Subject' />
  8. <input name="message" field="message" placeholder='Message' />
  9. <button type="submit">Submit</button>
  10. </form>
  11. </div>
  12. </div>
  13. );
  14.  
  15. const path = require('path');
  16. const express = require('express');
  17. const publicPath = path.join(__dirname, '../public');
  18. const port = process.env.PORT || 3000;
  19. const sgMail = require('@sendgrid/mail');
  20. sgMail.setApiKey(process.env.SENDGRID_API_KEY);
  21.  
  22. const app = express();
  23.  
  24. app.use(express.static(publicPath));
  25.  
  26. app.post('/contact', (req, res) => {
  27. const msg = {
  28. to: 'name.surname@gmail.com',
  29. from: 'name@inbox.lv',
  30. subject: 'Hello world',
  31. text: 'Hello plain world!',
  32. html: '<p>Hello HTML world!</p>',
  33. };
  34. sgMail
  35. .send(msg)
  36. .then(() => console.log('Mail sent successfully'))
  37. .catch(error => console.error(error.toString()))
  38. });
  39.  
  40. app.get('*', (req, res) => {
  41. res.sendFile(path.join(publicPath, 'index.html'));
  42. });
  43.  
  44.  
  45. app.listen(port, () => {
  46. console.log('Server is up');
  47. });
Add Comment
Please, Sign In to add comment