接上文 https://hostloc.com/thread-1067531-1-1.html
文中使用nginx来完成WebSocket转发和前端简易保护。
然而我就觉得不大合理,甲骨文本身线路好不到哪里去,套一个cloudflare更好,那岂不是ArgoTunnel直接起飞?既然都用CloudFlare了,直接用worker写一个脚本当nginx鉴权,这样连nginx都省了岂不美哉。
- const username = "XXX"//用户名
- const password = "123456"//密码
-
- const handle = (req) => {
- const auth = req.headers.get(‘Authorization’) || "Basic "
- if (auth.split(‘ ‘)[1] == btoa(username + ":" + password)) return fetch(req)
- return new Response(null, {
- status: 401,
- headers: {
- ‘WWW-Authenticate’: ‘Basic realm="CyanFalse’s Privae App!"’
- },
- body: ‘CyanFalse自留地!你无权进入!’
- })
- }
-
- addEventListener(‘fetch’, event => {
- event.respondWith(handle(event.request))
- })
复制代码
|