# Quick Reference Cheat Sheet ## 🚀 Quick Commands ### Add New API Endpoint ```bash # 1. Edit routes/api.js - add your endpoint # 2. Test locally PORT=3001 npm start # 3. Test endpoint curl "http://localhost:3001/api/your-endpoint" # 4. Deploy git add . && git commit -m "Add new API endpoint" # Then use manual deployment method ``` ### Add New HTML Page ```bash # 1. Add route to routes/pages.js # 2. Create view in views/your-page.ejs # 3. Update navigation in views/layout.ejs # 4. Test and deploy ``` ### Add New Documentation ```bash # 1. Create content/your-doc.md # 2. Auto-appears at /docs # 3. Available at /docs/your-doc ``` ## 📁 File Structure Quick Reference ``` api/ ├── app.js # Main server entry point ├── package.json # Dependencies and scripts ├── Procfile # Dokku process definition ├── Dockerfile # Container configuration ├── routes/ │ ├── api.js # JSON API endpoints │ ├── pages.js # HTML page routes │ └── docs.js # Documentation system ├── views/ │ ├── layout.ejs # Base template │ ├── index.ejs # Home page │ ├── about.ejs # About page │ └── [other-pages].ejs # Additional pages ├── content/ │ ├── api-reference.md # API documentation │ ├── deployment.md # Deployment guide │ └── [your-docs].md # Your documentation └── public/ ├── css/style.css # Styles └── js/app.js # Client-side JS ``` ## 🌐 Live URLs - **Main Site**: https://api.app.lobott.com - **API Explorer**: https://api.app.lobott.com/api-explorer - **Documentation**: https://api.app.lobott.com/docs - **Health Check**: https://api.app.lobott.com/health - **API Base**: https://api.app.lobott.com/api ## 🔧 Common API Patterns ### GET Endpoint with Query Parameters ```javascript router.get('/items', (req, res) => { const { limit = 10, category } = req.query; let results = data; if (category) { results = data.filter(item => item.category === category); } results = results.slice(0, parseInt(limit)); res.json({ success: true, count: results.length, data: results }); }); ``` ### GET Endpoint with Path Parameters ```javascript router.get('/items/:id', (req, res) => { const item = data.find(i => i.id === parseInt(req.params.id)); if (!item) { return res.status(404).json({ success: false, message: 'Item not found' }); } res.json({ success: true, data: item }); }); ``` ### POST Endpoint ```javascript router.post('/items', (req, res) => { const { name, category } = req.body; if (!name || !category) { return res.status(400).json({ success: false, message: 'Name and category are required' }); } const newItem = { id: Date.now(), name, category, created: new Date().toISOString() }; data.push(newItem); res.status(201).json({ success: true, data: newItem }); }); ``` ## 🎨 EJS Template Patterns ### Basic Page Template ```html

<%= title %>

<%= description %>

``` ### Data Iteration ```html <% if (items && items.length > 0) { %> <% } else { %>

No items found.

<% } %> ``` ### Conditional Content ```html <% if (user.isAdmin) { %>

Admin Controls

<% } %> ``` ## 📋 Deployment Checklist - [ ] Test locally on port 3001 - [ ] Commit changes to git - [ ] Create deployment archive - [ ] Upload to server - [ ] Build and deploy Docker container - [ ] Verify health endpoint - [ ] Test new features - [ ] Check logs for errors ## 🐛 Troubleshooting ### Port Issues ```bash # Kill processes on port 3000 lsof -ti:3000 | xargs kill -9 2>/dev/null || true ``` ### Container Issues ```bash # Check container status ssh root@104.248.219.197 "docker ps -a | grep api" # View logs ssh root@104.248.219.197 "docker logs api.web.1 --tail 20" # Restart container ssh root@104.248.219.197 "docker restart api.web.1" ``` ### Git Issues ```bash # Reset if needed git reset --hard HEAD git clean -fd # Force push if necessary git push origin main --force ``` ## 🔍 Testing Commands ```bash # Health check curl "https://api.app.lobott.com/health" # API endpoints curl "https://api.app.lobott.com/api" curl "https://api.app.lobott.com/api/users" curl "https://api.app.lobott.com/api/search?q=test" # With JSON formatting curl -s "https://api.app.lobott.com/api/users" | jq . ``` This cheat sheet provides quick access to the most common operations for your Multi-API application.