arcjet js
v1.0.0-alpha.34
ArcJetは、開発者がわずか数行のコードでアプリを保護するのに役立ちます。レートの制限、ボット保護、電子メール検証、および一般的な攻撃に対する防御を実装します。
これは、JS用のさまざまなArcJetオープンソースパッケージを含むモノレポです。
@arcjet/bunパッケージを使用してください。npm:@arcjet/denoパッケージを使用します。@arcjet/nestパッケージを使用します。@arcjet/nextパッケージを使用します。@arcjet/nodeパッケージを使用します。@arcjet/remixパッケージを使用します。@arcjet/sveltekitパッケージを使用します。 Discord Serverに参加するか、サポートのために手を差し伸べてください。
https://example.arcjet.com(ソースコード)でArcJet保護アプリをライブでお試しください。
docs.arcjet.comでドキュメントを読んでください。
以下のアークジェットレートの制限例は、トークンバケットレート制限ルールを適用します。これは、ログインしている場合、IDに基づいてユーザーを識別するルートに適用されます。バケットは、10トークンの最大容量で構成され、10秒ごとに5トークン補充します。各リクエストは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ボット保護ドキュメントを参照してください。
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 :sdk for deno。@arcjet/nest :nestjsのSDK。@arcjet/next :sdk for the next.jsフレームワーク。@arcjet/node :sdk for node.js.@arcjet/remix :sdk for remix。@arcjet/sveltekit :sveltekit for sdk。@arcjet/analyze :ローカル分析エンジン。@arcjet/headers :ヘッダークラスのarcjet拡張機能。@arcjet/ip :リクエストの発生IPを見つけるためのユーティリティ。@arcjet/redact :文字列からの編集&unedactの機密情報。nosecone :安全なヘッダーでResponseを保護します。@nosecone/next :安全なヘッダーでnext.jsアプリケーションを保護します。@nosecone/sveltekit :安全なヘッダーでSveltekitアプリケーションを保護します。arcjet :JS SDK Core。@arcjet/body :node.js incomingMessageからボディを抽出するためのユーティリティ。@arcjet/decorate :情報で応答を飾るためのユーティリティ。@arcjet/duration :seconds integersへの持続時間文字列を解析するためのユーティリティ。@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に基づいてライセンスされています。