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)
25
+
-[Test a "ban" remediation](#test-a-ban-remediation)
26
+
-[Test a "captcha" remediation](#test-a-captcha-remediation)
25
27
26
28
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
27
29
28
30
## Technical overview
29
31
30
32
The implementation uses Next.js App Router with middleware and API routes.
31
33
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.
34
+
**Important Note**: Starting from Next.js 15.5, the middleware now supports the Node.js runtime, which is required for
35
+
the CrowdSec bouncer to function properly. You will need Next.js version 15.5 or higher to use this implementation. The
36
+
middleware configuration includes `runtime: 'nodejs'` to enable this feature. For compatibility reasons, we still use
37
+
custom API routes (`/api/crowdsec/remediation` and `/api/crowdsec/captcha`) to handle the bouncer logic separately from
38
+
the middleware.
33
39
34
40
**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.
41
+
42
+
- The Next.js configuration (`next.config.ts`) includes a custom Webpack plugin to copy font files from the
43
+
`svg-captcha-fixed` library, making them available at runtime for captcha generation.
36
44
- 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.
45
+
- Environment variables are loaded from `.env` files in the `nextjs` directory using `dotenv` and `dotenv-safe` for
46
+
validation.
38
47
39
48
### Middleware (`src/middleware.ts`)
40
49
@@ -44,12 +53,12 @@ The middleware intercepts all requests and calls the CrowdSec API:
44
53
exportasyncfunctionmiddleware(req:NextRequest) {
45
54
// Check CrowdSec remediation using helper function
46
55
constres=awaitcheckRequestRemediation(req);
47
-
56
+
48
57
if (res) {
49
58
// Return ban/captcha wall if remediation is required
50
59
return res;
51
60
}
52
-
61
+
53
62
returnNextResponse.next();
54
63
}
55
64
@@ -95,7 +104,7 @@ export async function POST(req: Request) {
0 commit comments