@arcjet/inspect
弧喷 检查SDK所作决定的公用事业.
这是什么?
Arcjet将大量的元数据附于每个决定中. 此软件包的存在可以更容易地与Arcjet 决策进行互动, 以便通用 模式.
我什么时候用这个?
您可以直接访问决定的元数据, 但您可以使用此软件包 常见模式.
安装
这套方案只是无害环境管理. 在 Node.js 用 npm 安装 :
npm install @arcjet/inspect
使用
import http from "node:http";
import arcjet, { detectBot } from "@arcjet/next";
import { isMissingUserAgent } from "@arcjet/inspect";
// Get your Arcjet key at <https://app.arcjet.com>.
// Set it as an environment variable instead of hard coding it.
const arcjetKey = process.env.ARCJET_KEY;
if (!arcjetKey) {
throw new Error("Cannot find `ARCJET_KEY` environment variable");
}
const aj = arcjet({
key: arcjetKey,
rules: [
// `detectBot` lets you manage automated clients and bots.
detectBot({ allow: [], mode: "LIVE" }),
],
});
const server = http.createServer(async function (
request: http.IncomingMessage,
response: http.ServerResponse,
) {
const decision = await aj.protect(request);
if (decision.isDenied()) {
response.writeHead(403, { "Content-Type": "application/json" });
response.end(JSON.stringify({ message: "Forbidden" }));
return;
}
if (decision.results.some(isMissingUserAgent)) {
response.writeHead(403, { "Content-Type": "application/json" });
response.end(JSON.stringify({ message: "You are a bot!" }));
return;
}
response.writeHead(200, { "Content-Type": "application/json" });
response.end(JSON.stringify({ message: "Hello world" }));
});
server.listen(8000);
API 密码
此软件包导出标识符
isMissingUserAgent, (中文(简体) ),
isSpoofedBot,以及
isVerifiedBot。 。 。 .
没有默认导出 .
此套件导出否 类型脚本 类型.
isMissingUserAgent(result)
确定机器人规则是否检测到缺失的请求
User-Agent 头曰. 您可能想要屏蔽这样的请求, 因为缺少
User-Agent 信头是恶意请求的好指标,因为它是
建议
HTTP 语义学 从 IETF 调取。 。 。 .
参数
result(单位:千美元)ArcjetRuleResult(中文(简体) ) ——由Arcjet决定产生的规则
回返
此函数返回 true 如果机器人规则的结果是 LIVE 编辑
请求没有 User-Agent 标题, false 如果机器人规则的结果是
LIVE 请求中有一个 User-Agent 页眉,或 undefined 如果规则
结果是非机器人或 DRY_RUN (单位:千美元)boolean | undefined) (中文(简体) ).
可用性
使用时可用瓶保护 detectBot。 。 。 .
见 瓶装保护 打开
docs.arcjet.com
需要更多信息.
isSpoofedBot(result)
确定一个机器人规则结果是否检测到被窃取的请求 。 你也许想 封锁这些请求,因为这些请求很可能被窃取.
参数
result(单位:千美元)ArcjetRuleResult(中文(简体) ) ——由Arcjet决定产生的规则
回返
此函数返回 true 如果机器人规则的结果是 LIVE 检测
一个被刺穿的机器人, false 如果机器人规则的结果是 LIVE 没有检测到
被刺杀的机器人,或 undefined 如果规则结果是非机器人或 DRY_RUN
(单位:千美元)boolean | undefined) (中文(简体) ).
可用性
使用时可用瓶保护 detectBot。 。 。 .
见 瓶装保护 打开
docs.arcjet.com
需要更多信息.
isVerifiedBot(result)
确定一个bot规则结果是否检测到一个经过验证的bot. 你也许想 允许此类请求或忽略其他信号.
参数
result(单位:千美元)ArcjetRuleResult(中文(简体) ) ——由Arcjet决定产生的规则
回返
此函数返回 true 如果机器人规则的结果是 LIVE 检测
一个经证实的机器人, false 如果机器人规则的结果是 LIVE 没有检测到
经核实的机器人,或 undefined 如果规则结果是非机器人或 DRY_RUN
(单位:千美元)boolean | undefined) (中文(简体) ).
可用性
使用时可用瓶保护 detectBot。 。 。 .
见 瓶装保护 打开
docs.arcjet.com
需要更多信息.