Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. const express = require('express');
  2. const bodyParser = require('body-parser');
  3.  
  4. const app = express();
  5.  
  6. const doMadlib = (params) => {
  7. const {adjective1, adjective2, adjective3, adverb, name, pronoun, noun, place} = params;
  8. return (
  9. `There's a ${adjective1} new ${name} in ${place} and ${pronoun} has everybody` +
  10. `talking. Stunningly ${adjective2} and ${adverb} ${adjective3}, all the cool kids know it.` +
  11. `However, ${name} has a secret - ${name}'s a vile vampire. \n` +
  12. `Will it end with a bite, or with a stake through the ${noun}?`);
  13. };
  14.  
  15. // GET requests to the root of the server
  16. app.get('/', (req, res) => res.send(doMadlib(req.query)));
  17. __________________________________________________________________________________________________________________________________
  18.  
  19. 'use strict';
  20.  
  21. // Solution to A/B test drill
  22. // ==========================
  23.  
  24. const express = require('express');
  25. const cookieParser = require('cookie-parser');
  26.  
  27. const app = express();
  28.  
  29. const AB_COOKIE_NAME = 'a-b-test';
  30.  
  31. app.use(cookieParser());
  32. app.use(express.static('public'));
  33.  
  34.  
  35. const assignAb = () => ['a', 'b'][Math.floor(Math.random() * 2)];
  36.  
  37. app.get('/', (req, res) => {
  38. const cookie = req.cookies[AB_COOKIE_NAME];
  39. if (cookie === undefined) {
  40. res.cookie(AB_COOKIE_NAME, assignAb(), {});
  41. }
  42. res.sendFile(__dirname + '/views/index.html');
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement