65afa886af
Frontend API_BASE is /api in production, so health check was hitting /api/health which didn't exist. Added /api/health on the server and removed the now-unnecessary separate nginx /health proxy rule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { Hono } from 'hono';
|
|
import { cors } from 'hono/cors';
|
|
import { logger } from 'hono/logger';
|
|
import { serve } from '@hono/node-server';
|
|
import { auth } from './routes/auth';
|
|
import { savesRouter } from './routes/saves';
|
|
import { leaderboardRouter } from './routes/leaderboard';
|
|
import { invitesRouter } from './routes/invites';
|
|
import { runMigrations } from './db';
|
|
import { seedAdmin } from './db/seed';
|
|
|
|
if (!process.env.JWT_SECRET) {
|
|
console.error('FATAL: JWT_SECRET environment variable is required');
|
|
process.exit(1);
|
|
}
|
|
|
|
const app = new Hono();
|
|
|
|
app.use('*', logger());
|
|
app.use('*', cors({
|
|
origin: process.env.CORS_ORIGIN
|
|
? process.env.CORS_ORIGIN.split(',')
|
|
: ['http://localhost:5173', 'http://localhost:5174', 'http://localhost:5175', 'http://localhost:5178'],
|
|
allowMethods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
allowHeaders: ['Content-Type', 'Authorization'],
|
|
}));
|
|
|
|
app.get('/health', (c) => c.json({ status: 'ok', version: '0.1.0' }));
|
|
app.get('/api/health', (c) => c.json({ status: 'ok', version: '0.1.0' }));
|
|
|
|
app.get('/api/config', (c) => c.json({
|
|
requireInvite: process.env.REQUIRE_INVITE !== 'false',
|
|
userInvitations: parseInt(process.env.USER_INVITATIONS || '0', 10),
|
|
}));
|
|
|
|
app.route('/api/auth', auth);
|
|
app.route('/api/saves', savesRouter);
|
|
app.route('/api/leaderboard', leaderboardRouter);
|
|
app.route('/api/invites', invitesRouter);
|
|
|
|
const port = Number(process.env.PORT) || 3001;
|
|
|
|
console.log(`AI Tycoon API server starting on port ${port}...`);
|
|
|
|
await runMigrations();
|
|
await seedAdmin();
|
|
|
|
serve({ fetch: app.fetch, port });
|