1 Star 1 Fork 0

masx200 / deno-dns-over-https-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dns_records_authentication.tsx 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
masx200 提交于 2024-02-22 17:06 . Update dns_records_authentication.tsx
import {
Context,
NextFunction,
RetHandler,
} from "https://cdn.jsdelivr.net/gh/masx200/deno-http-middleware@3.3.0/mod.ts";
import { dns_records_path_name } from "./dns_records_path_name.tsx";
/**
* 使用 DNS 记录进行身份验证的中间件函数
* @param context 请求上下文
* @param next 下一个中间件函数
* @returns Promise<RetHandler> 返回处理结果
*/
export async function dns_records_authentication(
context: Context,
next: NextFunction,
): Promise<RetHandler> {
const token = Deno.env.get("token");
if (
new URL(context.request.url).pathname === dns_records_path_name()
) {
if (
("Bearer " + token) !== context.request.headers.get("Authorization")
) {
return {
status: 401,
body: "unauthorized",
headers: {
"WWW-Authenticate": 'Bearer realm="example"',
},
};
}
return await next();
}
return await next();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/masx200/deno-dns-over-https-server.git
git@gitee.com:masx200/deno-dns-over-https-server.git
masx200
deno-dns-over-https-server
deno-dns-over-https-server
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891