import { serve } from '@hono/node-server' import { Hono } from 'hono' import { cors } from 'hono/cors' import { logger } from 'hono/logger' import { config } from './config' import { prisma } from './prisma' import { closeRedis, redis } from './redis' import { authRoutes } from './auth/routes' const app = new Hono() app.use('*', logger()) app.use( '*', cors({ origin: (origin) => { if (!origin) return null return config.corsOrigins.includes(origin) ? origin : null }, allowHeaders: ['authorization', 'content-type'], allowMethods: ['GET', 'POST', 'PUT', 'OPTIONS'], credentials: true }) ) app.get('/health', async (c) => { const redisOk = (await redis.send('PING', [])) === 'PONG' return c.json({ ok: true, service: 'atnmy-stdo-auth', redis: redisOk ? 'ok' : 'error' }, redisOk ? 200 : 503) }) app.route('/auth', authRoutes) process.on('SIGINT', async () => { await closeRedis() await prisma.$disconnect() process.exit(0) }) serve({ fetch: app.fetch, port: config.port }, (info) => { console.log(`Auth server listening on http://localhost:${info.port}`) })