惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
TaoSecurity Blog
TaoSecurity Blog
Schneier on Security
Schneier on Security
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
O
OpenAI News
W
WeLiveSecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Hacker News: Front Page
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
Help Net Security
Help Net Security
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
S
Security @ Cisco Blogs
Latest news
Latest news
AWS News Blog
AWS News Blog
U
Unit 42
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Know Your Adversary
Know Your Adversary
Scott Helme
Scott Helme
博客园 - 司徒正美
B
Blog RSS Feed
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker
Google Online Security Blog
Google Online Security Blog
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Last Week in AI
Last Week in AI
月光博客
月光博客
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
SegmentFault 最新的问题
NISL@THU
NISL@THU
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
小众软件
小众软件

日常系列 on 打工人日志

Proxmox VE(PVE) 更新到最新版本 iStoreOS(旁路由)使用openclash实现dns劫持 异常流量分析:图片库服务黑客入侵 openwrt 硬盘扩容 搭建ip地址检索服务 通知:《打工人日报》迁移到独立板块 黑群晖最新安装教程 推荐一下 容器云资源 2010年的天涯神贴聊房价 如何礼貌回绝不合理的需求 逆境和成长-2022年终总结 优雅的使用Conda管理python环境 shell功能脚本集合 Cloudflare Zero Trust 内网穿透 headscale 部署使用 羊了个羊小程序 破解通关 RocketMQ k8s部署 4主4从集群 linux服务器 删除空间却未释放 VSCode插件推荐=> Code Runner ant build.xml 编写 记录一次上门打散工 Ant中如何添加第三方jar包依赖 linux 网络测速 网心云挂机教程 | 轻松实现睡后收入~ Proxmox VE 在线扩容磁盘分区 centos7.9 网络配置 RocketMQ 安装和启动 安装 minIO Azure S3网关 logrotate 日志滚动的使用 安装配置 Terraform rsync 文件同步 获取用户浏览器默认语言设置,自动判断跳转不同网站 linux系统开启root权限 163企业邮箱设置教程 2021年第50周记 自建服务器内网穿透 树莓派搭建k3s 优秀英语教材的选择
github 国内代理访问下载
2023-04-11 · via 日常系列 on 打工人日志
1#例子
2git clone https://github.jobcher.com/gh/https://github.com/jobcher/blog.git
  1'use strict'
  2
  3/**
  4 * static files (404.html, sw.js, conf.js)
  5 */
  6const ASSET_URL = 'https://jobcher.github.io/'
  7// 前缀,如果自定义路由为example.com/gh/*,将PREFIX改为 '/gh/',注意,少一个杠都会错!
  8const PREFIX = '/gh/'
  9// 分支文件使用jsDelivr镜像的开关,0为关闭,默认关闭
 10const Config = {
 11    jsdelivr: 0
 12}
 13
 14const whiteList = [] // 白名单,路径里面有包含字符的才会通过,e.g. ['/username/']
 15
 16/** @type {RequestInit} */
 17const PREFLIGHT_INIT = {
 18    status: 204,
 19    headers: new Headers({
 20        'access-control-allow-origin': '*',
 21        'access-control-allow-methods': 'GET,POST,PUT,PATCH,TRACE,DELETE,HEAD,OPTIONS',
 22        'access-control-max-age': '1728000',
 23    }),
 24}
 25
 26
 27const exp1 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:releases|archive)\/.*$/i
 28const exp2 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:blob|raw)\/.*$/i
 29const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-).*$/i
 30const exp4 = /^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+?\/.+$/i
 31const exp5 = /^(?:https?:\/\/)?gist\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+$/i
 32const exp6 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/tags.*$/i
 33
 34/**
 35 * @param {any} body
 36 * @param {number} status
 37 * @param {Object<string, string>} headers
 38 */
 39function makeRes(body, status = 200, headers = {}) {
 40    headers['access-control-allow-origin'] = '*'
 41    return new Response(body, {status, headers})
 42}
 43
 44
 45/**
 46 * @param {string} urlStr
 47 */
 48function newUrl(urlStr) {
 49    try {
 50        return new URL(urlStr)
 51    } catch (err) {
 52        return null
 53    }
 54}
 55
 56
 57addEventListener('fetch', e => {
 58    const ret = fetchHandler(e)
 59        .catch(err => makeRes('cfworker error:\n' + err.stack, 502))
 60    e.respondWith(ret)
 61})
 62
 63
 64function checkUrl(u) {
 65    for (let i of [exp1, exp2, exp3, exp4, exp5, exp6]) {
 66        if (u.search(i) === 0) {
 67            return true
 68        }
 69    }
 70    return false
 71}
 72
 73/**
 74 * @param {FetchEvent} e
 75 */
 76async function fetchHandler(e) {
 77    const req = e.request
 78    const urlStr = req.url
 79    const urlObj = new URL(urlStr)
 80    let path = urlObj.searchParams.get('q')
 81    if (path) {
 82        return Response.redirect('https://' + urlObj.host + PREFIX + path, 301)
 83    }
 84    // cfworker 会把路径中的 `//` 合并成 `/`
 85    path = urlObj.href.substr(urlObj.origin.length + PREFIX.length).replace(/^https?:\/+/, 'https://')
 86    if (path.search(exp1) === 0 || path.search(exp5) === 0 || path.search(exp6) === 0 || path.search(exp3) === 0 || path.search(exp4) === 0) {
 87        return httpHandler(req, path)
 88    } else if (path.search(exp2) === 0) {
 89        if (Config.jsdelivr) {
 90            const newUrl = path.replace('/blob/', '@').replace(/^(?:https?:\/\/)?github\.com/, 'https://cdn.jsdelivr.net/gh')
 91            return Response.redirect(newUrl, 302)
 92        } else {
 93            path = path.replace('/blob/', '/raw/')
 94            return httpHandler(req, path)
 95        }
 96    } else if (path.search(exp4) === 0) {
 97        const newUrl = path.replace(/(?<=com\/.+?\/.+?)\/(.+?\/)/, '@$1').replace(/^(?:https?:\/\/)?raw\.(?:githubusercontent|github)\.com/, 'https://cdn.jsdelivr.net/gh')
 98        return Response.redirect(newUrl, 302)
 99    } else {
100        return fetch(ASSET_URL + path)
101    }
102}
103
104
105/**
106 * @param {Request} req
107 * @param {string} pathname
108 */
109function httpHandler(req, pathname) {
110    const reqHdrRaw = req.headers
111
112    // preflight
113    if (req.method === 'OPTIONS' &&
114        reqHdrRaw.has('access-control-request-headers')
115    ) {
116        return new Response(null, PREFLIGHT_INIT)
117    }
118
119    const reqHdrNew = new Headers(reqHdrRaw)
120
121    let urlStr = pathname
122    let flag = !Boolean(whiteList.length)
123    for (let i of whiteList) {
124        if (urlStr.includes(i)) {
125            flag = true
126            break
127        }
128    }
129    if (!flag) {
130        return new Response("blocked", {status: 403})
131    }
132    if (urlStr.startsWith('github')) {
133        urlStr = 'https://' + urlStr
134    }
135    const urlObj = newUrl(urlStr)
136
137    /** @type {RequestInit} */
138    const reqInit = {
139        method: req.method,
140        headers: reqHdrNew,
141        redirect: 'manual',
142        body: req.body
143    }
144    return proxy(urlObj, reqInit)
145}
146
147
148/**
149 *
150 * @param {URL} urlObj
151 * @param {RequestInit} reqInit
152 */
153async function proxy(urlObj, reqInit) {
154    const res = await fetch(urlObj.href, reqInit)
155    const resHdrOld = res.headers
156    const resHdrNew = new Headers(resHdrOld)
157
158    const status = res.status
159
160    if (resHdrNew.has('location')) {
161        let _location = resHdrNew.get('location')
162        if (checkUrl(_location))
163            resHdrNew.set('location', PREFIX + _location)
164        else {
165            reqInit.redirect = 'follow'
166            return proxy(newUrl(_location), reqInit)
167        }
168    }
169    resHdrNew.set('access-control-expose-headers', '*')
170    resHdrNew.set('access-control-allow-origin', '*')
171
172    resHdrNew.delete('content-security-policy')
173    resHdrNew.delete('content-security-policy-report-only')
174    resHdrNew.delete('clear-site-data')
175
176    return new Response(res.body, {
177        status,
178        headers: resHdrNew,
179    })
180}
1git config --global https.proxy http://127.0.0.1:1080
2#取消设置
3git config --global --unset https.proxy