arcjet js
v1.0.0-alpha.34
ARCJET仅在几行代码中帮助开发人员保护其应用程序。实施费率限制,机器人保护,电子邮件验证和防御常见攻击。
这是包含JS的各种ARCJET开源软件包的MonorePo。
@arcjet/bun包。npm:@arcjet/deno软件包与我们的DENO快速启动指南。@arcjet/nest软件包。@arcjet/next软件包。@arcjet/node软件包。@arcjet/remix软件包。@arcjet/sveltekit软件包。 加入我们的Discord服务器或伸出援手获得支持。
尝试通过https://example.arcjet.com(源代码)实时ARCJET受保护的应用。
在docs.arcjet.com上阅读文档。
下面的ARCJET速率限制示例将令牌存储率率限制规则应用于一条路由,我们会根据用户识别其ID识别的路线。每个请求都会消耗5个令牌。
有关详细信息,请参见Arcjet next.js费率限制文档。
import arcjet , { tokenBucket } from "@arcjet/next" ;
import { NextResponse } from "next/server" ;
const aj = arcjet ( {
key : process . env . ARCJET_KEY ! , // Get your site key from https://app.arcjet.com
characteristics : [ "userId" ] , // track requests by a custom user ID
rules : [
// Create a token bucket rate limit. Other algorithms are supported.
tokenBucket ( {
mode : "LIVE" , // will block requests. Use "DRY_RUN" to log only
refillRate : 5 , // refill 5 tokens per interval
interval : 10 , // refill every 10 seconds
capacity : 10 , // bucket maximum capacity of 10 tokens
} ) ,
] ,
} ) ;
export async function GET ( req : Request ) {
const userId = "user123" ; // Replace with your authenticated user ID
const decision = await aj . protect ( req , { userId , requested : 5 } ) ; // Deduct 5 tokens from the bucket
console . log ( "Arcjet decision" , decision ) ;
if ( decision . isDenied ( ) ) {
return NextResponse . json (
{ error : "Too Many Requests" , reason : decision . reason } ,
{ status : 429 } ,
) ;
}
return NextResponse . json ( { message : "Hello world" } ) ;
}下面的ARCJET机器人保护示例将返回403个禁止响应,以确保我们肯定是自动化的所有请求。
有关详细信息,请参见Arcjet Node.js Bot保护文档。
import arcjet , { detectBot } from "@arcjet/node" ;
import http from "node:http" ;
const aj = arcjet ( {
key : process . env . ARCJET_KEY ! , // Get your site key from https://app.arcjet.com
rules : [
detectBot ( {
mode : "LIVE" , // will block requests. Use "DRY_RUN" to log only
// configured with a list of bots to allow from
// https://arcjet.com/bot-list
allow : [ ] , // "allow none" will block all detected bots
} ) ,
] ,
} ) ;
const server = http . createServer ( async function (
req : http . IncomingMessage ,
res : http . ServerResponse ,
) {
const decision = await aj . protect ( req ) ;
console . log ( "Arcjet decision" , decision ) ;
if ( decision . isDenied ( ) ) {
res . writeHead ( 403 , { "Content-Type" : "application/json" } ) ;
res . end ( JSON . stringify ( { error : "Forbidden" } ) ) ;
} else {
res . writeHead ( 200 , { "Content-Type" : "application/json" } ) ;
res . end ( JSON . stringify ( { message : "Hello world" } ) ) ;
}
} ) ;
server . listen ( 8000 ) ; 我们为此存储库中的各种软件包提供源代码,因此您可以通过下面的类别和描述找到特定的源代码。
@arcjet/bun :SDK for bun.sh.@arcjet/deno :deno的SDK。@arcjet/nest :sdk for nestjs。@arcjet/next :sdk for next.js框架。@arcjet/node :sdk for node.js。@arcjet/remix :SDK进行混音。@arcjet/sveltekit :SDK for Sveltekit。@arcjet/analyze :本地分析引擎。@arcjet/headers :标头类的ARCJET扩展。@arcjet/ip :用于查找请求的原始IP的实用程序。@arcjet/redact :从字符串中的编辑和未编辑敏感信息。nosecone :使用安全的标头保护您的Response 。@nosecone/next :使用安全标头保护您的Next.js应用程序。@nosecone/sveltekit :使用安全标头保护您的Sveltekit应用程序。arcjet :JS SDK核心。@arcjet/body :从node.js incoSingmessage中提取身体的实用程序。@arcjet/decorate :用于用信息装饰响应的实用程序。@arcjet/duration :分析持续时间字符串到秒数整数的实用程序。@arcjet/env :ARCJET变量的环境检测。@arcjet/logger :轻巧的记录器,镜像pino结构化记录器接口。@arcjet/protocol :JS接口到ARCJET协议。@arcjet/runtime :运行时检测。@arcjet/sprintf : util.format的无关替换。@arcjet/transport :Arcjet协议的传输机制。@arcjet/eslint-config :我们项目的自定义ESLINT配置。@arcjet/redact-wasm :敏感信息修复检测引擎。@arcjet/rollup-config :我们项目的自定义汇总配置。@arcjet/tsconfig :我们项目的自定义TSCONFIG。 该存储库遵循ARCJET支持策略。
该存储库遵循ARCJET安全策略。
根据Apache许可证获得许可,版本2.0。