ArcJet membantu pengembang melindungi aplikasi mereka hanya dalam beberapa baris kode. Menerapkan pembatasan tarif, perlindungan bot, verifikasi email, dan pertahanan terhadap serangan umum.
Ini adalah monorepo yang berisi berbagai paket open source arcjet untuk JS.
@arcjet/bun dengan panduan start cepat roti kami.npm:@arcjet/deno dengan Panduan Mulai Cepat Deno kami.@arcjet/nest dengan panduan start cepat NestJs kami.@arcjet/next dengan panduan start cepat berikutnya.js kami.@arcjet/node dengan panduan start cepat node.js kami.@arcjet/remix dengan panduan start cepat remix kami.@arcjet/sveltekit dengan panduan start cepat lsveltekit kami. Bergabunglah dengan server Discord kami atau hubungi dukungan.
Coba Aplikasi Lindung Arcjet Langsung di https://example.arcjet.com (kode sumber).
Baca dokumen di docs.arcjet.com.
Contoh Batas Laju ArcJet di bawah ini berlaku aturan batas laju bucket token ke rute di mana kami mengidentifikasi pengguna berdasarkan ID mereka misalnya jika mereka masuk. Bucket dikonfigurasi dengan kapasitas maksimum 10 token dan mengisi ulang dengan 5 token setiap 10 detik. Setiap permintaan mengkonsumsi 5 token.
Lihat Dokumentasi Batas Tingkat ArcJet Next.js untuk detailnya.
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" } ) ;
}Contoh perlindungan bot arcjet di bawah ini akan mengembalikan respons terlarang 403 untuk semua permintaan dari klien yang kami yakin otomatis.
Lihat Dokumentasi Perlindungan Bot Arcjet Node.js untuk detailnya.
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 ) ; Kami menyediakan kode sumber untuk berbagai paket di repositori ini, sehingga Anda dapat menemukan yang spesifik melalui kategori dan deskripsi di bawah ini.
@arcjet/bun : SDK untuk Bun.sh.@arcjet/deno : SDK untuk Deno.@arcjet/nest : SDK untuk NestJS.@arcjet/next : SDK untuk kerangka kerja selanjutnya.@arcjet/node : SDK untuk node.js.@arcjet/remix : SDK untuk remix.@arcjet/sveltekit : SDK untuk Sveltekit.@arcjet/analyze : mesin analisis lokal.@arcjet/headers : Ekstensi ArcJet dari kelas header.@arcjet/ip : Utilitas untuk menemukan IP yang berasal dari permintaan.@arcjet/redact : redact & unredact informasi sensitif dari string.nosecone : Lindungi Response Anda dengan header yang aman.@nosecone/next : Lindungi aplikasi Next.js Anda dengan header yang aman.@nosecone/sveltekit : Lindungi aplikasi Sveltekit Anda dengan header yang aman.arcjet : JS SDK Core.@arcjet/body : utilitas untuk mengekstraksi tubuh dari node.js incomingmessage.@arcjet/decorate : Utilitas untuk mendekorasi tanggapan dengan informasi.@arcjet/duration : Utilitas untuk string durasi parsing menjadi bilangan bulat detik.@arcjet/env : Deteksi lingkungan untuk variabel arcjet.@arcjet/logger : Logger ringan yang mencerminkan antarmuka logger terstruktur pino.@arcjet/protocol : antarmuka js ke protokol arcjet.@arcjet/runtime : deteksi runtime.@arcjet/sprintf : penggantian platform-independen untuk util.format .@arcjet/transport : Mekanisme transportasi untuk protokol ArcJet.@arcjet/eslint-config : Custom Eslint Config untuk proyek kami.@arcjet/redact-wasm : mesin deteksi redaksi informasi sensitif.@arcjet/rollup-config : konfigurasi rollup khusus untuk proyek kami.@arcjet/tsconfig : kustom tsconfig untuk proyek kami. Repositori ini mengikuti kebijakan dukungan ArcJet.
Repositori ini mengikuti kebijakan keamanan ArcJet.
Lisensi di bawah lisensi Apache, versi 2.0.