mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 18:41:08 +02:00
refactor: consolidate codebase — remove archived code, deduplicate packages, standardize middleware
- Delete 17 server-archived/ directories (consolidated into apps/api/) - Delete apps-archived/ (clock, wisekeep) and services-archived/ (it-landing, ollama-metrics-proxy) - Fix type safety: replace all `any` casts in cross-app-queries.ts with proper Local* types - Remove duplicate shared-auth-stores package (identical copy of shared-auth-ui/stores/) - Remove duplicate theme store from shared-stores (canonical version in shared-theme) - Migrate memoro-server rate-limiter to shared-hono/rateLimitMiddleware - Migrate uload-server JWT auth + error handler to shared-hono (authMiddleware, errorHandler) - Migrate arcade-server error handling to shared-hono - Merge shared-profile-ui and shared-app-onboarding into shared-ui - Unify /clock route into /times/clock, remove redirect stubs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7ee57b7afd
commit
d8ce4eaf34
309 changed files with 172 additions and 21667 deletions
|
|
@ -8,7 +8,12 @@
|
|||
import { Hono } from 'hono';
|
||||
import { cors } from 'hono/cors';
|
||||
import { logger } from 'hono/logger';
|
||||
import { authMiddleware, errorHandler, notFoundHandler } from '@manacore/shared-hono';
|
||||
import {
|
||||
authMiddleware,
|
||||
errorHandler,
|
||||
notFoundHandler,
|
||||
rateLimitMiddleware,
|
||||
} from '@manacore/shared-hono';
|
||||
|
||||
import { memoRoutes } from './routes/memos';
|
||||
import { spaceRoutes } from './routes/spaces';
|
||||
|
|
@ -20,7 +25,6 @@ import { cleanupRoutes } from './routes/cleanup';
|
|||
import { meetingRoutes } from './routes/meetings';
|
||||
import { meetingWebhookRoutes } from './routes/meetings-webhooks';
|
||||
import { COSTS } from './lib/credits';
|
||||
import { rateLimiter } from './middleware/rate-limiter';
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
|
|
@ -51,7 +55,7 @@ app.use(
|
|||
|
||||
app.use(
|
||||
'/api/v1/*',
|
||||
rateLimiter({
|
||||
rateLimitMiddleware({
|
||||
windowMs: 60_000,
|
||||
max: 100,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
import type { MiddlewareHandler } from 'hono';
|
||||
|
||||
interface RateLimiterOptions {
|
||||
/** Time window in milliseconds (default: 60000 = 1 minute) */
|
||||
windowMs?: number;
|
||||
/** Max requests per window per IP (default: 100) */
|
||||
max?: number;
|
||||
}
|
||||
|
||||
interface RateLimitEntry {
|
||||
count: number;
|
||||
resetAt: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple in-memory rate limiter middleware for Hono.
|
||||
* Limits requests per IP address within a sliding time window.
|
||||
*/
|
||||
export function rateLimiter(options: RateLimiterOptions = {}): MiddlewareHandler {
|
||||
const windowMs = options.windowMs ?? 60_000;
|
||||
const max = options.max ?? 100;
|
||||
const store = new Map<string, RateLimitEntry>();
|
||||
|
||||
// Periodic cleanup of expired entries every 5 minutes
|
||||
setInterval(() => {
|
||||
const now = Date.now();
|
||||
for (const [key, entry] of store) {
|
||||
if (now >= entry.resetAt) {
|
||||
store.delete(key);
|
||||
}
|
||||
}
|
||||
}, 5 * 60_000);
|
||||
|
||||
return async (c, next): Promise<void | Response> => {
|
||||
const ip =
|
||||
c.req.header('x-forwarded-for')?.split(',')[0]?.trim() ||
|
||||
c.req.header('x-real-ip') ||
|
||||
'unknown';
|
||||
|
||||
const now = Date.now();
|
||||
let entry = store.get(ip);
|
||||
|
||||
if (!entry || now >= entry.resetAt) {
|
||||
entry = { count: 0, resetAt: now + windowMs };
|
||||
store.set(ip, entry);
|
||||
}
|
||||
|
||||
entry.count++;
|
||||
|
||||
c.header('X-RateLimit-Limit', String(max));
|
||||
c.header('X-RateLimit-Remaining', String(Math.max(0, max - entry.count)));
|
||||
c.header('X-RateLimit-Reset', String(Math.ceil(entry.resetAt / 1000)));
|
||||
|
||||
if (entry.count > max) {
|
||||
return c.json(
|
||||
{ error: 'Too many requests', retryAfter: Math.ceil((entry.resetAt - now) / 1000) },
|
||||
429
|
||||
);
|
||||
}
|
||||
|
||||
await next();
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue