Admin role added, dev side has hot reload again, characters AND groups tied to accounts now.
This commit is contained in:
58
server/src/app.ts
Normal file
58
server/src/app.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { Hono } from 'hono';
|
||||
import { cors } from 'hono/cors';
|
||||
import { logger } from 'hono/logger';
|
||||
import { serveStatic } from '@hono/node-server/serve-static';
|
||||
import { sessionMiddleware } from './middleware/session';
|
||||
import authRoutes from './routes/auth';
|
||||
import publicRoutes from './routes/public';
|
||||
import groupRoutes from './routes/groups';
|
||||
import memberRoutes from './routes/members';
|
||||
import adminRoutes from './routes/admin';
|
||||
import characterRoutes from './routes/characters';
|
||||
|
||||
export function createApp() {
|
||||
const app = new Hono();
|
||||
|
||||
// Middleware
|
||||
app.use('*', logger());
|
||||
|
||||
// CORS - configured via CORS_ORIGINS env var
|
||||
const corsOrigins = process.env.CORS_ORIGINS
|
||||
? process.env.CORS_ORIGINS.split(',')
|
||||
: ['http://localhost:3000', 'http://localhost:3001', 'http://localhost:4000'];
|
||||
|
||||
app.use(
|
||||
'*',
|
||||
cors({
|
||||
origin: corsOrigins,
|
||||
credentials: true,
|
||||
allowHeaders: ['Content-Type', 'Authorization'],
|
||||
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
|
||||
maxAge: 3600,
|
||||
})
|
||||
);
|
||||
|
||||
// Session middleware for all routes
|
||||
app.use('*', sessionMiddleware);
|
||||
|
||||
// API Routes
|
||||
app.route('/api', authRoutes);
|
||||
app.route('/api', publicRoutes);
|
||||
app.route('/api/group', groupRoutes);
|
||||
app.route('/api/group', memberRoutes);
|
||||
app.route('/api/admin', adminRoutes);
|
||||
app.route('/api/characters', characterRoutes);
|
||||
|
||||
// Health check
|
||||
app.get('/api/health', (c) => c.json({ status: 'ok', timestamp: new Date().toISOString() }));
|
||||
|
||||
// Serve static files from React build
|
||||
const frontendPath = process.env.FRONTEND_BUILD_PATH || '../os-league-tools-master/build';
|
||||
|
||||
app.use('/*', serveStatic({ root: frontendPath }));
|
||||
|
||||
// SPA fallback - serve index.html for all non-API routes
|
||||
app.get('*', serveStatic({ path: `${frontendPath}/index.html` }));
|
||||
|
||||
return app;
|
||||
}
|
||||
Reference in New Issue
Block a user