You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Test a "bypass" remediation](#test-a-bypass-remediation)
23
+
-[Test a "ban" remediation](#test-a-ban-remediation)
24
+
-[Test a "captcha" remediation](#test-a-captcha-remediation)
23
25
24
26
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
25
27
26
28
## Technical overview
27
29
28
30
The implementation uses Next.js App Router with middleware and API routes.
29
31
30
-
**Important Note**: We cannot use the CrowdSec bouncer directly in the Next.js middleware because middleware runs on the Edge Runtime, which doesn't have access to Node.js APIs that the bouncer requires. While Next.js offers an experimental `nodeMiddleware` feature that would allow Node.js APIs in middleware, we prefer not to rely on experimental features for production use. Instead, we use a custom API route (`/api/crowdsec`) that runs in the Node.js runtime and can access the full bouncer functionality.
32
+
**Important Note**: Starting from Next.js 15.5, the middleware now supports the Node.js runtime, which is required for the CrowdSec bouncer to function properly. You will need Next.js version 15.5 or higher to use this implementation. The middleware configuration includes `runtime: 'nodejs'`to enable this feature. For compatibility reasons, we still use custom API routes (`/api/crowdsec/remediation` and `/api/crowdsec/captcha`) to handle the bouncer logic separately from the middleware.
31
33
32
-
**Additional Note**: We had to update the Next.js configuration (`next.config.ts`) to copy font files from the `svg-captcha-fixed` library to make them available at runtime. This is necessary because Next.js doesn't automatically include these assets in the build, and the captcha functionality requires access to these fonts to generate captcha images.
34
+
**Additional Notes**:
35
+
- The Next.js configuration (`next.config.ts`) includes a custom Webpack plugin to copy font files from the `svg-captcha-fixed` library, making them available at runtime for captcha generation.
36
+
- The project now includes Tailwind CSS v4 for styling the captcha page and other UI components.
37
+
- Environment variables are loaded from `.env` files in the `nextjs` directory using `dotenv` and `dotenv-safe` for validation.
33
38
34
39
### Middleware (`src/middleware.ts`)
35
40
36
41
The middleware intercepts all requests and calls the CrowdSec API:
37
42
38
43
```js
39
44
exportasyncfunctionmiddleware(req:NextRequest) {
40
-
// Skip CrowdSec check for captcha route and non-HTML requests
41
-
if (pathname ==='/crowdsec-captcha'||!acceptHeader.includes('text/html')) {
0 commit comments