久久机这里只有精品,国产69精品一区二区亚洲孕妇,91精品国产综合久久婷婷香蕉,午夜久久久久久电影

最新活動(dòng):電腦PC端+手機(jī)端+微網(wǎng)站+自適應(yīng)網(wǎng)頁(yè)多模板選擇-建站388元起價(jià)!!!
當(dāng)前位置:主頁(yè) > 網(wǎng)站建設(shè) > 利用CloudflareWorkers加速Github建站文章

利用CloudflareWorkers加速Github建站文章

時(shí)間:2023-05-28 19:05:28 閱讀: 文章分類: 網(wǎng)站建設(shè) 作者: 建站小能手

導(dǎo)讀:建站文章建站文章 使用國(guó)內(nèi)的云服務(wù)器時(shí),對(duì)于Github是極其不友好的,經(jīng)常無(wú)法連接上,raw.githubusercontent.com域名也是已經(jīng)涼涼,git clone能seo網(wǎng)站優(yōu)化seo網(wǎng)站優(yōu)化培訓(xùn)。

seo網(wǎng)站優(yōu)化seo網(wǎng)站優(yōu)化培訓(xùn)

使用國(guó)內(nèi)的云服務(wù)器時(shí),對(duì)于Github是極其不友好的,經(jīng)常無(wú)法連接上,raw.githubusercontent.com域名也是已經(jīng)涼涼,git clone能連上的時(shí)候也是龜速。

所幸,發(fā)現(xiàn)了這一款工具,用過(guò)之后感覺(jué)渾身舒爽。

如果你以前沒(méi)有使用過(guò)Cloudflare Workers,可以參考這篇文章的詳細(xì)步驟:https://www.nbmao.com/archives/4324

這里就不多贅述了

Demo

https://git.haoduck.cf 建議是自己搭建一個(gè),自己搭建比較穩(wěn)定,Cloudflare Workers免費(fèi)套餐的每天10萬(wàn)請(qǐng)求數(shù)是綽綽有余的。如果只是偶爾用用,直接用這個(gè)也無(wú)妨。

使用方法

1.

加速下載文件

打開https://git.haoduck.cf,然后輸入要加速的鏈接(release文件等)

或者直接在鏈接前面加上https://git.haoduck.cf/ 示例: 從https://raw.githubusercontent.com/username/xxxxx/xxxxx變成https://git.haoduck.cf/raw.githubusercontent.com/username/xxxxx/xxxxx

2. 加速clone

將git clone https://github.com/username/xxx.git換成git clone https://git.haoduck.cf/github.com/username/xxx.git

更多詳見:Github

Cloudflare Workers代碼

'use strict' /** * static files (404.html, sw.js, conf.js) */ const ASSET_URL = 'https://hunshcn.github.io/gh-proxy' // 前綴,如果自定義路由為example.com/gh/*,將PREFIX改為 '/gh/',注意,少一個(gè)杠都會(huì)錯(cuò)! const PREFIX = '/' // git使用cnpmjs鏡像、分支文件使用jsDelivr鏡像的開關(guān),0為關(guān)閉,默認(rèn)開啟 const Config = { jsdelivr: 1, cnpmjs: 1 } /** @type {RequestInit} */ const PREFLIGHT_INIT = { status: 204, headers: new Headers({ 'access-control-allow-origin': '*', 'access-control-allow-met網(wǎng)站優(yōu)化seo培訓(xùn)hods': 'GET,POST,PUT,PATCH,TRACE,DELETE,HEAD,OPTIONS', 'access-control-max-age': '1728000', }), } /** * @param {any} body * @param {number} status * @param {Object<string, string>} headers */ function makeRes(body, status = 200, headers = {}) { headers['access-control-allow-origin'] = '*' return new Response(body, {status, headers}) } /** * @param {string} urlStr */ function newUrl(urlStr) { try { return new URL(urlStr) } catch (err) { return null } } addEventListener('fetch', e => { const ret = fetchHandler(e) .catch(err => makeRes('cfworker error:\n' + err.stack, 502)) 網(wǎng)站seo優(yōu)化培訓(xùn) e.respondWith(ret) }) /** * @param {FetchEvent} e */ async function fetchHandler(e) { const req = e.request const urlStr = req.url const urlObj = new URL(urlStr) let path = urlObj.searchParams.get('q') if (path) { return Response.redirect('https://' + urlObj.host + PREFIX + path, 301) } // cfworker 會(huì)把路徑中的 `//` 合并成 `/` path = urlObj.href.substr(urlObj.origin.length + PREFIX.length).replace(/^https?:\/+/, 'https://') const exp1 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:releases|archive)\/.*$/i const exp2 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:blob)\/.*$/i const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-).*$/i const exp4 = /^(?:https?:\/\/)?raw\.githubusercontent\.com\/.+?\/.+?\/.+?\/.+$/i if (path.search(exp1) === 0 || !Config.cnpmjs && (path.search(exp3) === 0 || path.search(exp4) === 0)) { return httpHandler(req, path) } else if (path.search(exp2) === 0) { if (Config.jsdelivr){ const newUrl = path.replace('/blob/', '@').replace(/^(?:https?:\/\/)?github\.com/, 'https://cdn.jsdelivr.net/gh') return Response.redirect(newUrl, 302) }else{ path = path.replace('/blob/', '/raw/') return httpHandler(req, path) } } else if (path.search(exp3) === 0) { const newUrl = path.replace(/^(?:https?:\/\/)?github\.com/, 'https://github.com.cnpmjs.org') return Response.redirect(newUrl, 302) } else if (path.search(exp4) === 0) { const newUrl = path.replace(/(?<=com\/.+?\/.+?)\/(.+?\/)/, '@$1').replace(/^(?:https?:\/\/)?raw\.githubusercontent\.com/, 'https://cdn.jsdelivr.net/gh') return Response.redirect(newUrl, 302) } else { return fetch(ASSET_URL + path) } } /** * @param {Request} req * @param {string} pathname */ function httpHandler(req, pathname) { const reqHdrRaw = req.headers // preflight if (req.method === 'OPTIONS' && reqHdrRaw.has('access-control-request-headers') ) { return new Response(null, PREFLIGHT_INIT) } let rawLen = '' const reqHdrNew = new Headers(reqHdrRaw) let urlStr = pathname if (urlStr.startsWith('github')) { urlStr = 'https://' + urlStr } const urlObj = newUrl(urlStr) /** @type {RequestInit} */ const reqInit = { method: req.method, headers: reqHdrNew, redirect: 'follow', body: req.body 網(wǎng)站seo優(yōu)化課程} return proxy(urlObj, reqInit, rawLen, 0) } /** * * @param {URL} urlObj * @param {RequestInit} reqInit */ async function proxy(urlObj, reqInit, rawLen) { const res = await fetch(urlObj.href, reqInit) const resHdrOld = res.headers const resHdrNew = new Headers(resHdrOld) // verify if (rawLen) { const newLen = resHdrOld.get('content-length') || '' const badLen = (rawLen !== newLen) if (badLen) { return makeRes(res.body, 400, { '--error': `bad len: ${newLen}, except: ${rawLen}`, 'access-control-expose-headers': '--error', }) } } const status = res.status resHdrNew.set('access-control-expose-headers', '*') resHdrNew.set('access-control-allow-origin', '*') resHdrNew.delete('content-security-policy') resHdrNew.delete('content-security-policy-report-only') resHdrNew.delete('clear-site-data') return new Response(res.body, { status, headers: resHdrNew, }) }相關(guān)seo網(wǎng)站優(yōu)化seo網(wǎng)站優(yōu)化培訓(xùn)。

關(guān)鍵詞標(biāo)簽: Cloudflare 加速Github

聲明: 本文由我的SEOUC技術(shù)文章主頁(yè)發(fā)布于:2023-05-28 ,文章利用CloudflareWorkers加速Github建站文章主要講述CloudFlare,加速Github網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請(qǐng)保留鏈接: http://www.bifwcx.com/article/web_11523.html

我的IDC 網(wǎng)站建設(shè)技術(shù)SEOUC.COM
專注網(wǎng)站建設(shè),SEO優(yōu)化,小程序設(shè)計(jì)制作搭建開發(fā)定制網(wǎng)站等,數(shù)千家網(wǎng)站定制開發(fā)案例,網(wǎng)站推廣技術(shù)服務(wù)。
  • 5000+合作客服
  • 8年從業(yè)經(jīng)驗(yàn)
  • 150+覆蓋行業(yè)
  • 最新熱門源碼技術(shù)文章

    主站蜘蛛池模板: 徐州市| 东阿县| 通江县| 清河县| 津市市| 堆龙德庆县| 三原县| 文山县| 东城区| 广河县| 古丈县| 江华| 英山县| 锡林郭勒盟| 龙岩市| 循化| 招远市| 大洼县| 万盛区| 邢台市| 石台县| 浦北县| 福贡县| 西吉县| 颍上县| 昌黎县| 神农架林区| 泸水县| 攀枝花市| 山阳县| 广南县| 兴宁市| 松滋市| 红原县| 苍梧县| 南靖县| 平谷区| 西平县| 久治县| 明溪县| 东乡县|