将 帐号:密码
通过BASE64加密,填到下面代码 const authorization
里面的 Basic
后面
admin:password
BASE64加密为 YWRtaW46cGFzc3dvcmQ=
/** http basic auth **/
const authorization = "Basic YWRtaW46cGFzc3dvcmQ=";
/** http basic auth **/
var basicauth;
addEventListener('fetch', event => {
console.log(event.request.headers.get("Authorization"));
if (event.request.headers.get("Authorization") !== authorization) {
return event.respondWith(new Response(
null, {
status: 401,
statusText: "'Authentication required.'",
body: "Unauthorized",
headers: {
"WWW-Authenticate": 'Basic realm="User Visible Realm"'
}
}
))
}
event.respondWith(handleRequest(event.request))
})
将代码插入到 workers 里面即可添加 basic auth 认证
Comments | NOTHING
该文章已经关闭评论