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:
fahed
2026-03-26 14:58:35 +03:00
parent 9c1552e439
commit e84d961536
11 changed files with 1111 additions and 10 deletions

25
server/src/config.ts Normal file
View File

@@ -0,0 +1,25 @@
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
const __dirname = dirname(fileURLToPath(import.meta.url));
dotenv.config({ path: resolve(__dirname, '..', '.env') });
export const server = {
port: parseInt(process.env.SERVER_PORT || '3001', 10),
};
export const salla = {
clientId: process.env.SALLA_CLIENT_ID || '',
clientSecret: process.env.SALLA_CLIENT_SECRET || '',
redirectUri: process.env.SALLA_REDIRECT_URI || 'http://localhost:3001/auth/callback',
accessToken: process.env.SALLA_ACCESS_TOKEN || '',
refreshToken: process.env.SALLA_REFRESH_TOKEN || '',
};
export const erp = {
apiUrl: process.env.ERP_API_URL || '',
apiCode: process.env.ERP_API_CODE || '',
username: process.env.ERP_USERNAME || '',
password: process.env.ERP_PASSWORD || '',
};