Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Echo Endpoint
- 'use strict';
- const express = require('express');
- const app = express();
- app.get('/echo/:what', (req, res) => {
- res.json({
- host: req.hostname,
- query: req.query,
- params: req.params
- });
- });
- // listen for requests :)
- app.listen(process.env.PORT || 8080, () => console.log(
- `Your app is listening on port ${process.env.PORT || 8080}`));
- // ==================================
- // Mad lib generator
- 'use strict';
- const express = require('express');
- const app = express();
- const doMadLib = (argument) => {
- const {adjective1, adjective2, adjective3, adverb, name, noun, place} = argument;
- return (
- `There's a ${adjective1} new ${name} in ${place} and everyone's ` +
- `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}?`);
- };
- app.get('/', (req, res) => res.send(doMadLib(req.query)));
- // listen for requests :)
- app.listen(process.env.PORT || 8080, () => console.log(
- `Your app is listening on port ${process.env.PORT || 8080}`));
- // ==================================
- // A/B
- 'use strict';
- const express = require('express');
- const cParser = require('cookie-parser');
- const app = express();
- const AB_COOKIE_NAME = 'a-b-test';
- app.use(cParser());
- app.use(express.static('public'));
- const accessAb = () => ['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, accessAb(), {});
- }
- res.sendFile(__dirname + '/views/index.html');
- });
- // listen for requests :)
- app.listen(process.env.PORT || 8080, () => console.log(
- `Your app is listening on port ${process.env.PORT || 8080 }`));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement