- Implemented forgot password and reset password routes in the backend. - Added email sending capabilities using Nodemailer for password reset requests. - Created ResetPassword page in the frontend for users to reset their passwords. - Updated user model to include reset token and expiry fields. - Integrated hiscores API with caching mechanism for improved performance. - Enhanced authentication modal to include forgot password option. - Updated environment configuration for SMTP settings.
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
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';
|
|
import hiscoresRoutes from './routes/hiscores';
|
|
|
|
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() }));
|
|
|
|
// Hiscores proxy - under /api so nginx routes correctly
|
|
app.route('/api/hiscores', hiscoresRoutes);
|
|
|
|
// 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;
|
|
}
|