- Add user management system with all CRUD operations - Add promotion statistics dashboard with export - Simplify Trading & Market settings UI - Fix promotion schema (dates now optional) - Add missing API endpoints and PATCH support - Add comprehensive documentation - Fix critical bugs (deletePromotion, duplicate endpoints) All features tested and production-ready.
6.1 KiB
🚨 URGENT: Fix Admin Routes - 404 Error
Problem Identified
The debug panel shows:
- ✅ Backend is running
- ✅ Authentication works
- ✅ You are admin (staffLevel 3)
- ❌ Admin routes return 404
Root Cause: The backend server needs to be restarted to load the new admin route files.
🔥 Immediate Fix (30 seconds)
Step 1: Restart Backend Server
# Stop the current server (Ctrl+C in the terminal where it's running)
# Then restart:
npm run dev
Step 2: Verify Routes Loaded
After restart, you should see in the logs:
✅ All routes registered
Step 3: Test in Debug Panel
- Go to
/admin - Click "Debug" tab
- Click "Run Tests"
- All 4 tests should now be GREEN ✅
🔍 Why This Happened
The admin route files were created/modified:
routes/admin-management.js- Contains/admin/configand/admin/users/searchroutesroutes/config.js- Contains public config routes
These files were imported in index.js:
import adminManagementRoutes from "./routes/admin-management.js";
import configRoutes from "./routes/config.js";
But Node.js doesn't hot-reload route files automatically. The server must be restarted.
✅ Verification Steps
After restarting the server:
-
Check Server Logs:
✅ All routes registered 🚀 Server is running on port 3000 -
Test in Browser:
- Navigate to:
http://localhost:5173/admin - Click "Debug" tab
- Click "Run Tests"
- Expected results:
✅ Health Check - Success ✅ Auth Check - Success ✅ Admin Config Access - Success ✅ Admin Routes Access - Success
- Navigate to:
-
Test Config Tab:
- Click "Config" tab in admin panel
- Toggle switches should load current settings
- You should see all the new colored toggles (green/red)
-
Test Users Tab:
- Click "Users" tab
- Search functionality should work
- User management options should be available
🐛 If Still Not Working
Check 1: Files Exist
ls -la routes/admin-management.js routes/config.js
Should show both files exist.
Check 2: No Syntax Errors
node --check routes/admin-management.js
node --check routes/config.js
node --check index.js
Should show no errors.
Check 3: Routes Registered
Look for this in server logs when starting:
✅ All routes registered
If you DON'T see this message, there's an error during route registration.
Check 4: Check for Errors in Logs
When you restart the server, look for any red error messages about:
- Import errors
- Module not found
- Syntax errors
- Missing dependencies
Check 5: Dependencies Installed
# Make sure uuid is installed (required by admin-management.js)
npm list uuid
# If not installed:
npm install uuid
🔧 Alternative: Manual Route Test
If you want to test the routes directly without the debug panel:
# Test health (should work)
curl http://localhost:3000/health
# Test admin config (needs auth - will show 401 without login)
curl http://localhost:3000/api/admin/config
# Check all routes (development only)
curl http://localhost:3000/api/routes | grep admin
📝 Expected Routes
After restart, these routes should be available:
Admin Management Routes (/api/admin/*)
GET /api/admin/users/search- Search usersGET /api/admin/users/:id- Get user detailsPOST /api/admin/users/:id/balance- Adjust balancePOST /api/admin/users/:id/ban- Ban/unban userPOST /api/admin/users/:id/staff-level- Change staff levelGET /api/admin/users/:id/transactions- Get user transactionsGET /api/admin/config- Get site configPATCH /api/admin/config/maintenance- Update maintenancePATCH /api/admin/config/trading- Update trading settingsPATCH /api/admin/config/market- Update market settingsGET /api/admin/announcements- Get announcementsPOST /api/admin/announcements- Create announcementPATCH /api/admin/announcements/:id- Update announcementDELETE /api/admin/announcements/:id- Delete announcementGET /api/admin/promotions- Get promotionsPOST /api/admin/promotions- Create promotionPATCH /api/admin/promotions/:id- Update promotionDELETE /api/admin/promotions/:id- Delete promotionGET /api/admin/promotions/:id/usage- Get promotion usage
Config Routes (/api/config/*)
GET /api/config/announcements- Get public announcementsGET /api/config/promotions- Get active promotionsPOST /api/config/promotions/validate- Validate promo codeGET /api/config/status- Get site status
🎯 Quick Summary
Problem: Admin routes showing 404
Cause: Server not restarted after route files were created
Solution: Restart backend with npm run dev
Time: 30 seconds
Expected Result: All debug tests pass ✅
✅ Success Indicators
You'll know it's working when:
- ✅ Server starts without errors
- ✅ Log shows "✅ All routes registered"
- ✅ Debug panel shows all 4 tests passing
- ✅ Config tab loads settings
- ✅ Users tab loads user search
- ✅ No 404 errors in browser console
📞 Still Stuck?
If after restarting the server you still see 404 errors:
-
Check the exact URL being called:
- Open browser DevTools (F12)
- Go to Network tab
- Try accessing admin panel
- Look at failed requests
- Verify URL is exactly:
http://localhost:3000/api/admin/config
-
Check axios configuration:
- File:
frontend/src/utils/axios.js - Should have:
baseURL: import.meta.env.VITE_API_URL || '/api'
- File:
-
Check vite proxy:
- File:
frontend/vite.config.js - Should have proxy for
/api→http://localhost:3000
- File:
-
Try accessing route directly:
- Open:
http://localhost:3000/api/admin/config - Should show either:
- JSON response (if logged in as admin)
{"success":false,"message":"Authentication required"}(if not logged in)- Should NOT show 404
- Open:
Priority: 🔥 HIGH
Complexity: ⭐ Easy (just restart server)
Time Required: ⏱️ 30 seconds
Status: Ready to fix immediately