mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
1.5 KiB
1.5 KiB
Setup Middleware
Status: ✅ Implemented | Edge middleware enforcing setup wizard completion
Overview
Edge runtime middleware intercepts all non-API requests to gate access until the setup wizard finishes. It uses a lightweight API check so Prisma is never invoked inside the Edge sandbox.
Key Details
- Location:
src/middleware.ts - Skips:
/api/*,/_next/*,/static/*, any path containing.(static assets) - Fetches
/api/setup/statuswith headerx-middleware-request: true - Redirects:
- Setup incomplete →
/setup(unless already there) - Setup complete →
/when user visits/setup
- Setup incomplete →
- Fetch origin priority:
SETUP_CHECK_BASE_URLenv (optional override, e.g.http://rmab-internal:3030)- Incoming request origin (
request.nextUrl.origin) - Loopback fallback
http://127.0.0.1:${PORT|3030}
- On repeated failures the middleware logs once per request but allows traffic to avoid blocking users
API/Interfaces
GET /api/setup/status
Headers: x-middleware-request: true
Response: { setupComplete: boolean }
Critical Issues
- Reverse proxies that terminate TLS on a hostname unreachable from inside the container should set
SETUP_CHECK_BASE_URLto an internal origin (or rely on the loopback fallback if port exposure allows it). - Ensure the fallback port stays in sync with the app server port (
PORTenv, defaults to 3030 in Docker images).