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。