refactor: migrate API routes to Hono sub-router
- Create Hono router in api.ts
- Convert 6 API endpoints to Hono format:
- GET /api/deposit/balance
- POST /api/deposit/deduct
- POST /api/test
- POST /api/chat
- POST /api/contact
- GET /api/metrics
- Use Hono CORS middleware for /contact
- Remove manual handleApiRequest and handleContactPreflight
- Integrate with main app via app.route('/api', apiRouter)
Benefits:
- Cleaner declarative routing (44 insertions, 48 deletions)
- Built-in CORS middleware
- Better code organization
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Env, EmailMessage, ProvisionMessage, MessageBatch } from './types';
|
||||
import { sendMessage, setWebhook, getWebhookInfo } from './telegram';
|
||||
import { handleWebhook } from './routes/webhook';
|
||||
import { handleApiRequest } from './routes/api';
|
||||
import { apiRouter } from './routes/api';
|
||||
import { handleHealthCheck } from './routes/health';
|
||||
import { parseBankSMS } from './services/bank-sms-parser';
|
||||
import { matchPendingDeposit } from './services/deposit-matcher';
|
||||
@@ -69,8 +69,8 @@ app.get('/webhook-info', async (c) => {
|
||||
return c.json(result);
|
||||
});
|
||||
|
||||
// API routes
|
||||
app.all('/api/*', (c) => handleApiRequest(c.req.raw, c.env, new URL(c.req.url)));
|
||||
// API routes - use Hono router
|
||||
app.route('/api', apiRouter);
|
||||
|
||||
// Telegram Webhook
|
||||
app.post('/webhook', (c) => handleWebhook(c.req.raw, c.env));
|
||||
|
||||
Reference in New Issue
Block a user