| const axios = require('axios'); |
| const fs = require('fs'); |
| const path = require('path'); |
|
|
| const BASE_URL = 'http://localhost:3000/api'; |
|
|
| const endpoints = [ |
| |
| { method: 'POST', url: '/auth/register', label: 'Auth Register' }, |
| { method: 'POST', url: '/auth/login', label: 'Auth Login' }, |
| { method: 'POST', url: '/auth/verify-otp', label: 'Auth Verify OTP' }, |
| { method: 'POST', url: '/auth/refresh-token', label: 'Auth Refresh Token' }, |
| |
| |
| { method: 'GET', url: '/auth/profile', label: 'Auth Profile' }, |
|
|
| |
| { method: 'GET', url: '/dashboard/stats', label: 'Dashboard Stats' }, |
| { method: 'GET', url: '/dashboard/activity', label: 'Dashboard Activity' }, |
| { method: 'GET', url: '/dashboard/live-tracking', label: 'Dashboard Live Tracking (Mobile)' }, |
| { method: 'GET', url: '/dashboard/live-tracking-web', label: 'Dashboard Live Tracking (Web)' }, |
| { method: 'GET', url: '/dashboard/recent-absorptions', label: 'Dashboard Recent Absorptions' }, |
|
|
| |
| { method: 'GET', url: '/drivers', label: 'Get All Drivers' }, |
| { method: 'POST', url: '/drivers', label: 'Create Driver' }, |
| |
| |
| { method: 'GET', url: '/eway-bills', label: 'Get E-Way Bills' }, |
| { method: 'GET', url: '/eway-bills/stats', label: 'Get E-Way Bills Stats' }, |
| { method: 'POST', url: '/eway-bills', label: 'Create E-Way Bill' }, |
|
|
| |
| { method: 'GET', url: '/packages/history', label: 'Package History (Mobile)' }, |
| { method: 'GET', url: '/packages/history-web', label: 'Package History (Web)' }, |
|
|
| |
| { method: 'POST', url: '/deliveries/create', label: 'Create Delivery (Public)' }, |
| { method: 'GET', url: '/deliveries/assigned', label: 'Assigned Deliveries' }, |
|
|
| |
| { method: 'GET', url: '/absorption/map-data', label: 'Absorption Map Data' }, |
| { method: 'GET', url: '/absorption/active', label: 'Absorption Active' }, |
| |
| |
| { method: 'GET', url: '/virtual-hubs', label: 'Virtual Hubs List' }, |
| ]; |
|
|
| async function checkEndpoints() { |
| let output = '# API Verification Results (With JSON Body)\n\n'; |
| console.log('Checking API Endpoints...'); |
|
|
| for (const ep of endpoints) { |
| try { |
| const config = { |
| method: ep.method, |
| url: BASE_URL + ep.url, |
| validateStatus: function (status) { |
| return status < 600; |
| } |
| }; |
| |
| const response = await axios(config); |
| let statusLabel = 'Unknown'; |
| let icon = 'β'; |
| |
| if (response.status >= 200 && response.status < 300) { |
| statusLabel = 'Success'; |
| icon = 'β
'; |
| } else if (response.status === 401 || response.status === 403) { |
| statusLabel = 'Protected (Auth Required)'; |
| icon = 'π'; |
| } else if (response.status === 400) { |
| statusLabel = 'Bad Request (Endpoint Active)'; |
| icon = 'β οΈ'; |
| } else if (response.status === 404) { |
| statusLabel = 'Not Found'; |
| icon = 'β'; |
| } else { |
| statusLabel = `Error ${response.status}`; |
| icon = 'β οΈ'; |
| } |
|
|
| |
| output += `### ${icon} ${ep.label}\n`; |
| output += `**Endpoint**: \`${ep.method} ${ep.url}\`\n`; |
| output += `**Status**: ${response.status} (${statusLabel})\n`; |
|
|
| |
| if (ep.method === 'GET' && response.status >= 200 && response.status < 300) { |
| output += `**Response Body**:\n`; |
| output += '```json\n'; |
| output += JSON.stringify(response.data, null, 2); |
| output += '\n```\n'; |
| } else if (ep.method === 'POST') { |
| output += `**Response**: ${statusLabel}\n`; |
| } |
|
|
| output += '---\n\n'; |
|
|
| } catch (error) { |
| output += `### π ${ep.label}\n`; |
| output += `**Endpoint**: \`${ep.method} ${ep.url}\`\n`; |
| output += `**Error**: Network Error (${error.message})\n\n`; |
| } |
| } |
|
|
| fs.writeFileSync(path.join(__dirname, 'api_verification_results.md'), output); |
| console.log('Verification complete. Detailed results saved to api_verification_results.md'); |
| } |
|
|
| checkEndpoints(); |
|
|