Created
June 22, 2023 00:34
-
-
Save theJenix/9fab2d89beafda2b0dee41b33043997a to your computer and use it in GitHub Desktop.
sandwich-ipsum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const loremIpsum = require('lorem-ipsum').loremIpsum; | |
const app = express(); | |
const port = 3000; | |
// Sandwich Ipsum words | |
const sandwichWords = [ | |
'lettuce', 'tomato', 'cheese', 'bacon', 'mayonnaise', | |
'mustard', 'ham', 'turkey', 'pickles', 'onion', | |
'chicken', 'avocado', 'cheddar', 'roast beef', | |
'salami', 'cucumber', 'honey mustard', 'pepperoni', | |
'white bread', 'whole wheat bread', 'rye bread', | |
'baguette', 'ciabatta', 'pita', 'submarine', | |
'club sandwich', 'panini', 'wrap', 'grilled', | |
'toasted', 'open-faced', 'deli', 'picnic', | |
'beach', 'lunch', 'brunch', 'picnic', 'barbecue' | |
]; | |
// Generate Sandwich Ipsum text | |
function generateSandwichIpsum() { | |
return loremIpsum({ | |
count: 5, // Number of "sandwich" paragraphs | |
units: 'paragraphs', | |
words: sandwichWords | |
}); | |
} | |
// Serve the HTML page | |
app.get('/', (req, res) => { | |
res.send(` | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Sandwich Ipsum Generator</title> | |
<style> | |
.italic { | |
font-style: italic; | |
} | |
</style> | |
</head> | |
<body> | |
<button onclick="generateIpsum()">Generate Sandwich Ipsum</button> | |
<p><span id="ipsumText"></span></p> | |
<script> | |
function generateIpsum() { | |
fetch('/generate') | |
.then(response => response.text()) | |
.then(data => { | |
const ipsumText = document.getElementById('ipsumText'); | |
ipsumText.innerHTML = data; | |
}); | |
} | |
</script> | |
</body> | |
</html> | |
`); | |
}); | |
// Generate the Sandwich Ipsum text on request | |
app.get('/generate', (req, res) => { | |
const ipsum = generateSandwichIpsum(); | |
res.send(ipsum); | |
}); | |
// Start the server | |
app.listen(port, () => { | |
console.log(`Server running on http://localhost:${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment