properly enable arcjet
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
parent
0465dda09f
commit
885faf6453
@ -4,7 +4,6 @@ import "./globals.css";
|
||||
import React from "react";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/button";
|
||||
import Head from "next/head";
|
||||
|
||||
const inter = Inter({
|
||||
subsets: ["latin"],
|
||||
@ -41,14 +40,6 @@ export default function RootLayout({
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<Head>
|
||||
<link
|
||||
rel="alternate"
|
||||
type="application/rss+xml"
|
||||
title="RSS"
|
||||
href="/blog.rss"
|
||||
/>
|
||||
</Head>
|
||||
<body
|
||||
className={`${inter.variable} ${podkova.variable} ${inter.className}`}
|
||||
>
|
||||
|
@ -1,17 +0,0 @@
|
||||
import arcjet, { createMiddleware, shield } from "@arcjet/next";
|
||||
export const config = {
|
||||
// matcher tells Next.js which routes to run the middleware on.
|
||||
// This runs the middleware on all routes except for static assets.
|
||||
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
|
||||
};
|
||||
const aj = arcjet({
|
||||
key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com
|
||||
rules: [
|
||||
// Protect against common attacks with Arcjet Shield
|
||||
shield({
|
||||
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
|
||||
}),
|
||||
],
|
||||
});
|
||||
// Pass any existing middleware with the optional existingMiddleware prop
|
||||
export default createMiddleware(aj);
|
40
middleware.ts
Normal file
40
middleware.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import arcjet, { detectBot } from "@arcjet/next";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export const config = {
|
||||
// matcher tells Next.js which routes to run the middleware on.
|
||||
// This runs the middleware on all routes except for static assets.
|
||||
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
|
||||
};
|
||||
|
||||
const aj = arcjet({
|
||||
key: process.env.ARCJET_KEY!,
|
||||
rules: [
|
||||
detectBot({
|
||||
mode: "LIVE",
|
||||
allow: [
|
||||
"CATEGORY:SEARCH_ENGINE",
|
||||
"CATEGORY:PREVIEW",
|
||||
"CATEGORY:SOCIAL",
|
||||
],
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
export default async function middleware(request: NextRequest) {
|
||||
const decision = await aj.protect(request);
|
||||
|
||||
if (
|
||||
// If this deny comes from a bot rule then block the request. You can
|
||||
// customize this logic to fit your needs e.g. changing the status code.
|
||||
decision.isDenied() &&
|
||||
decision.reason.isBot()
|
||||
) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 403 });
|
||||
} else if (decision.isErrored()) {
|
||||
console.warn("Arcjet error", decision.reason.message);
|
||||
return NextResponse.json({ error: "Bad request" }, { status: 400 });
|
||||
} else {
|
||||
return NextResponse.next();
|
||||
}
|
||||
}
|
1515
package-lock.json
generated
1515
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user