Files
edueasy/middleware.ts
renato97 a3360ec6e4 feat: fase 2+3 — expansion masiva multi-perfil + bug fixes + hardening
Fase 2 (expansion):
- Francesca: +6 etapas matematicas (5-10), +7 etapas lectura (3-9), +2 ortografia
- Sebastian: +8 etapas matematicas (4-11), +6 lectura, +3 historia, +3 geografia, +1 banderas
- Nuevas paginas: ortografia, lectura, geografia, matematicas
- ~900 ejercicios nuevos, paridad ~500 por perfil

Fase 3 (bug fixes + hardening):
- Fix: SessionLog auto-create en grade route
- Fix: engine cache (no borrar antes de revisar)
- Fix: FSRS cards actualizadas en flujo curriculum
- Fix: responseMs real (no hardcodeado 3000)
- Fix: options dentro de content en sebastian etapa-1
- Fix: trazo-letra consonantes crash
- Security: execFileSync anti-command-injection en TTS
- DB: 18 cascade deletes + indices + unique constraints
- APIs debug: reset, state, seed
- Docker: espeak-ng + prisma + user/group
- E2E: 23 tests nuevos (curriculum-flow.spec.ts)
- Code review: tailwind colors, middleware dev mode, eslint config

Verificado: tsc exit 0, build exit 0, 61 E2E tests pass
2026-07-25 22:07:28 -03:00

56 lines
1.4 KiB
TypeScript

import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
const CHILD_HOST = "mate"
const PARENT_HOST = "simulacro"
const isDev = process.env.NODE_ENV === "development"
export function middleware(request: NextRequest) {
const hostname = request.headers.get("host") || ""
const { pathname } = request.nextUrl
if (
pathname.startsWith("/api") ||
pathname.startsWith("/_next") ||
pathname.startsWith("/static") ||
pathname === "/favicon.ico"
) {
return NextResponse.next()
}
if (isDev) {
return NextResponse.next()
}
if (hostname.includes(CHILD_HOST)) {
if (
pathname === "/" ||
pathname.startsWith("/child") ||
pathname.startsWith("/francesca") ||
pathname.startsWith("/sebastian")
) {
return NextResponse.next()
}
const url = request.nextUrl.clone()
url.pathname = "/"
return NextResponse.rewrite(url)
}
if (hostname.includes(PARENT_HOST)) {
if (pathname === "/" || pathname.startsWith("/parent")) {
return NextResponse.next()
}
const url = request.nextUrl.clone()
url.pathname = `/parent${pathname === "/" ? "" : pathname}`
return NextResponse.rewrite(url)
}
const url = request.nextUrl.clone()
url.pathname = "/child"
return NextResponse.rewrite(url)
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
}