daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 207 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let express = require('express');
  2. const nodemailer = require('nodemailer');  // va chercher nodemailer
  3. let router = express.Router();
  4.  
  5. /* GET home page. */
  6. router.get('/', function (req, res, next) {
  7.   res.render('index', { title: 'Express' });
  8. });
  9.  
  10. //ajout des routes
  11. router.get('/forms-:numeroArticle(\\d+)', function (req, res, next) {
  12.   console.log(req.params.numeroArticle);
  13.   console.log(req.query.level);
  14. });
  15. router.post('/forms-:numeroArticle(\\d+)', function (req, res, next) {
  16.   console.log(req.params.numeroArticle);
  17.   console.log(req.body.name);
  18. });
  19.  
  20. router.get('/coucou-pug', function (req, res, next) {
  21.   res.render('coucou', { sayHello: 'Hello buddy' });
  22. });
  23.  
  24. // Middleware
  25. router.get('/superMiddleware', (req, res, next) => {
  26.   console.log('hello superTupperware');
  27.   next();
  28. }, (req, res, next) => {
  29.   res.send('Hello world');
  30. });
  31.  
  32. //session-in et session-out
  33. router.get('/session-in', function (req, res) {
  34.   req.session.song = 'be bop a lula';
  35.   res.send("j'ai crée ma variable");
  36. })
  37. router.get('/session-out', (req, res) => {
  38.   res.send(req.session.song);
  39. })
  40.  
  41. // ENVOYER UN EMAIL ----------------------------------------------------------
  42. const transport = nodemailer.createTransport({
  43.   host: "smtp.mailtrap.io",
  44.   port: 2525,
  45.   auth: {
  46.     user: "7ff2cb5b75d132",
  47.     pass: "72bf5768e5d4c5"
  48.   }
  49. });
  50.  
  51. router.get('/askForCookiesRecipe', (req, res) => {
  52.   transport.sendMail({
  53.     from: "b6140e33f6-996218@inbox.mailtrap.io",
  54.     to: "supergrandma@yopmail.com",
  55.     subject: "Ta recette de cookies",
  56.     text: "Bonjour",
  57.     html: "<b>Bonjour Supergrand-ma, comment ca va?....... </b>"
  58.   }, (error, response) => {
  59.     if (error) {
  60.       console.log(error);
  61.     } else {
  62.       res.send(response);
  63.     }
  64.   });
  65.  
  66. });
  67.  
  68.  
  69.  
  70. module.exports = router;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top