feat: convert server to TypeScript + add ERP API proxy
- Migrate server/index.js → modular TS structure (config, routes, services) - Add ERP proxy: GET /api/erp/sales proxies Hono ERP API with server-side auth - JWT token cached server-side, auto-refreshes on 401 - ERP credentials stay server-side only (no VITE_ prefix) - Vite dev proxy routes /api/erp → localhost:3001 - Preserve existing Salla OAuth integration Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Router, Request, Response } from 'express';
|
||||
import { fetchSales, isConfigured } from '../services/erpClient';
|
||||
|
||||
const router = Router();
|
||||
|
||||
// GET /api/erp/sales?startDate=2025-01-01T00:00:00&endDate=2025-01-31T00:00:00
|
||||
router.get('/sales', async (req: Request, res: Response) => {
|
||||
if (!isConfigured()) {
|
||||
res.status(503).json({ error: 'ERP API not configured on server' });
|
||||
return;
|
||||
}
|
||||
|
||||
const { startDate, endDate } = req.query;
|
||||
|
||||
if (!startDate || !endDate) {
|
||||
res.status(400).json({ error: 'startDate and endDate query params required' });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await fetchSales(startDate as string, endDate as string);
|
||||
res.json(data);
|
||||
} catch (err) {
|
||||
console.error('ERP fetch error:', (err as Error).message);
|
||||
res.status(502).json({ error: 'Failed to fetch from ERP API', details: (err as Error).message });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/erp/status
|
||||
router.get('/status', (_req: Request, res: Response) => {
|
||||
res.json({ configured: isConfigured() });
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user