Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const bodyParser = require('body-parser');
- const app = express();
- const doMadlib = (params) => {
- const {adjective1, adjective2, adjective3, adverb, name, pronoun, noun, place} = params;
- return (
- `There's a ${adjective1} new ${name} in ${place} and ${pronoun} has everybody` +
- `talking. Stunningly ${adjective2} and ${adverb} ${adjective3}, all the cool kids know it.` +
- `However, ${name} has a secret - ${name}'s a vile vampire. \n` +
- `Will it end with a bite, or with a stake through the ${noun}?`);
- };
- // GET requests to the root of the server
- app.get('/', (req, res) => res.send(doMadlib(req.query)));
- __________________________________________________________________________________________________________________________________
- 'use strict';
- // Solution to A/B test drill
- // ==========================
- const express = require('express');
- const cookieParser = require('cookie-parser');
- const app = express();
- const AB_COOKIE_NAME = 'a-b-test';
- app.use(cookieParser());
- app.use(express.static('public'));
- const assignAb = () => ['a', 'b'][Math.floor(Math.random() * 2)];
- app.get('/', (req, res) => {
- const cookie = req.cookies[AB_COOKIE_NAME];
- if (cookie === undefined) {
- res.cookie(AB_COOKIE_NAME, assignAb(), {});
- }
- res.sendFile(__dirname + '/views/index.html');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement