Skip to content

Instantly share code, notes, and snippets.

@theJenix
Created June 22, 2023 00:34
Show Gist options
  • Save theJenix/9fab2d89beafda2b0dee41b33043997a to your computer and use it in GitHub Desktop.
Save theJenix/9fab2d89beafda2b0dee41b33043997a to your computer and use it in GitHub Desktop.
sandwich-ipsum
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