Guest User

Untitled

a guest
Aug 20th, 2018
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. const express = require('express');
  2. const router = express.Router();
  3. const nodemailer = require("nodemailer");
  4.  
  5.  
  6. router.use('/superMiddleware', function (req, res, next) {
  7. console.log("Hello middleware");
  8. next();
  9. }, function (req, res, next) {
  10. res.send('Hello world');
  11. next();
  12. });
  13.  
  14. router.get('/askForCookiesRecipe', (req, res, next) => {
  15. // Création de la méthode de transport de l'email
  16. const smtpTransport = nodemailer.createTransport("SMTP", {
  17. service: "Gmail",
  18. auth: {
  19. user: "maGrandMa@gmail.com",
  20. pass: "userPass"
  21. }
  22. });
  23.  
  24. smtpTransport.sendMail({
  25. from: "Deer Wild <deer@wild.com>", // Expediteur
  26. to: "wildCodeSchool@hotmail.com", // Destinataires
  27. subject: "Coucou !", // Sujet
  28. text: "Hello world ✔", // plaintext body
  29. html: "<b>Hello world ✔</b>" // html body
  30. }, (error, response) => {
  31. if (error) {
  32. console.log(error);
  33. } else {
  34. console.log("Message sent: " + response.message);
  35. }
  36. });
  37. });
  38.  
  39.  
  40.  
  41. /* GET Session in. */
  42. router.get('/session-in', (req, res, next) => {
  43. // Initialisation de la variable de sessions "song"
  44. req.session.song = "be bop a lula";
  45. console.log(req.session.song);
  46. res.end();
  47. });
  48.  
  49. /* GET Session out. */
  50. router.get('/session-out', (req, res, next) => {
  51. res.send(`the song is ${req.session.song}`);
  52. next();
  53. });
  54.  
  55.  
  56. /* GET home page. */
  57. router.get('/', function (req, res, next) {
  58. res.render('index', {
  59. title: 'Express'
  60. });
  61. next();
  62. });
  63.  
  64. module.exports = router;
Add Comment
Please, Sign In to add comment