/** * Backend Server * * Hono API server with auth routes pre-configured. */ import { Hono } from 'hono'; import { cors } from 'hono/cors'; import { getAuthUrl, handleCallback, getConfigFromEnv } from './modules/auth'; const app = new Hono(); // CORS for frontend app.use('/*', cors({ origin: ['http://localhost:5173', 'http://localhost:3005'], credentials: true, })); // Health check app.get('/health', (c) => c.json({ status: 'ok' })); // ============================================ // AUTH ROUTES // ============================================ const authConfig = getConfigFromEnv(); app.get('/auth/login', (c) => { return c.redirect(getAuthUrl(authConfig)); }); app.get('/auth/callback', async (c) => { const code = c.req.query('code'); if (!code) { return c.json({ error: 'No authorization code' }, 400); } try { const result = await handleCallback(code, authConfig); // Return token and user info // Frontend should store token and redirect return c.json(result); } catch (err) { const message = err instanceof Error ? err.message : 'Auth failed'; return c.json({ error: message }, 403); } }); // ============================================ // API ROUTES // ============================================ app.get('/api/me', async (c) => { // TODO: Validate token from Authorization header // Return current user info return c.json({ message: 'Implement me' }); }); // ============================================ // START SERVER // ============================================ const port = Number(process.env.PORT) || 3005; console.log(`[Server] Starting on port ${port}...`); export default { port, fetch: app.fetch, };