PYAE1994's picture
Upload folder using huggingface_hub
dd480ef verified
/**
* Cloudflare Worker - Main Entry Point
* Architecture: Thin API Gateway + Orchestrator
* Heavy logic is offloaded to external compute services (simulator, planner, compiler, validator)
*
* CF Workers Free Plan constraints:
* - 10ms CPU time limit per request
* - 128MB memory limit
* - No Cloudflare Queues
* - Limited KV operations
*/
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { logger } from 'hono/logger';
import { generateWorkflowRoute } from './routes/generate';
import { validateWorkflowRoute } from './routes/validate';
import { simulateWorkflowRoute } from './routes/simulate';
import { deployWorkflowRoute } from './routes/deploy';
import { approvalRoute } from './routes/approval';
import { activateWorkflowRoute } from './routes/activate';
import { reportsRoute } from './routes/reports';
import { healthRoute } from './routes/health';
import { authMiddleware } from './middleware/auth';
import { rateLimitMiddleware } from './middleware/rateLimit';
import { errorHandler } from './middleware/errorHandler';
import type { Env } from './types/env';
const app = new Hono<{ Bindings: Env }>();
// ─── Global Middleware ────────────────────────────────────────────────────────
app.use('*', cors({
origin: ['https://your-frontend.pages.dev', 'http://localhost:3000'],
allowHeaders: ['Content-Type', 'Authorization', 'X-API-Key'],
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
maxAge: 86400,
}));
app.use('*', logger());
app.use('*', errorHandler);
// ─── Public Routes ────────────────────────────────────────────────────────────
app.route('/health', healthRoute);
// ─── Protected Routes (require API auth) ─────────────────────────────────────
app.use('/api/*', authMiddleware);
app.use('/api/*', rateLimitMiddleware);
app.route('/api/workflows', generateWorkflowRoute);
app.route('/api/workflows', validateWorkflowRoute);
app.route('/api/workflows', simulateWorkflowRoute);
app.route('/api/workflows', deployWorkflowRoute);
app.route('/api/workflows', approvalRoute);
app.route('/api/workflows', activateWorkflowRoute);
app.route('/api/reports', reportsRoute);
// ─── 404 Handler ─────────────────────────────────────────────────────────────
app.notFound((c) => {
return c.json({
success: false,
error: 'Route not found',
available_routes: [
'POST /api/workflows/generate',
'POST /api/workflows/validate',
'POST /api/workflows/simulate',
'POST /api/workflows/deploy',
'POST /api/workflows/approve',
'POST /api/workflows/activate',
'GET /api/reports/workflow/:id',
'GET /api/reports/validation/:id',
'GET /api/reports/simulation/:id',
'GET /health',
],
}, 404);
});
export default app;