diff --git a/.github/workflows/autofix-ci.yml b/.github/workflows/autofix-ci.yml new file mode 100644 index 0000000..c1eed75 --- /dev/null +++ b/.github/workflows/autofix-ci.yml @@ -0,0 +1,38 @@ +name: autofix.ci +on: + push: + branches: + - main + + pull_request: {} + +permissions: + contents: read + +jobs: + autofix: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PNPM + run: corepack enable + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 20.x + cache: pnpm + + - name: Setup + run: npm i -g @antfu/ni + + - name: Install + run: ni --no-frozen-lockfile + + - name: Lint and fix + run: nr lint:fix + + - uses: autofix-ci/action@ea32e3a12414e6d3183163c3424a7d7a8631ad84 + with: + commit-message: "chore: apply automatic fixes" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index dec8bba..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: ClientWorker CI -on: - - push -jobs: - buildstatic: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup node - uses: actions/setup-node@v1 - with: - node-version: 16.x - - name: Cache node modules - uses: actions/cache@v1 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - - name: Install & Build - run: > - rm -rf .gitignore - - echo "node_modules" >> .gitignore - - echo "doc/node_modules" >> .gitignore - - npm i -D - - npm install -D webpack-cli webpack - - npm run build - - echo "clientworker.js.org" > ./dist/CNAME - - cd doc - - npm add --dev vitepress vue - - npm run "docs:build" - - - - - name: Deploy to GithubPage - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.TOKEN }} - publish_dir: ./dist - - - name: Publish to NPM - uses: JS-DevTools/npm-publish@v1 - with: - token: ${{ secrets.NPM }} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9892a18 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,87 @@ +name: CI + +on: + push: + branches: + - main + + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PNPM + run: corepack enable + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 20.x + cache: pnpm + + - name: Setup + run: npm i -g @antfu/ni + + - name: Install + run: nci + + - name: Lint + run: nr lint + + typecheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PNPM + run: corepack enable + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 20.x + cache: pnpm + + - name: Setup + run: npm i -g @antfu/ni + + - name: Install + run: nci + + - name: Typecheck + run: nr typecheck + + test: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + node: [16.x, 18.x, 20.x] + os: [ubuntu-latest, windows-latest, macos-latest] + fail-fast: false + + steps: + - uses: actions/checkout@v4 + + - name: Setup PNPM + run: corepack enable + + - name: Set node version to ${{ matrix.node }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node }} + cache: pnpm + + - name: Setup + run: npm i -g @antfu/ni + + - name: Install + run: nci + + - name: Test + run: nr test diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml new file mode 100644 index 0000000..b9a6210 --- /dev/null +++ b/.github/workflows/lock.yml @@ -0,0 +1,27 @@ +name: Lock Threads + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: {} + +permissions: + issues: write + pull-requests: write + +concurrency: + group: lock + +jobs: + action: + runs-on: ubuntu-latest + steps: + - uses: dessant/lock-threads@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + issue-inactive-days: "14" + issue-comment: | + This issue has been locked since it has been closed for more than 14 days. + + If you have found a concrete bug or regression related to it, please open a new [issue](./new/choose). If you have any other comments you should create a new [discussion](../discussions/new/choose). + process-only: issues diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b5f7f45 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,25 @@ +name: Release + +on: + push: + tags: + - "v*" + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v3 + with: + node-version: 20.x + + - run: npx changelogithub + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 2f43ada..f6a33e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,12 @@ +.cache +.DS_Store +.idea +*.log +*.tgz +coverage +dist +lib-cov +logs node_modules -package-lock.json -doc/node_modules -dist/ \ No newline at end of file +temp +docs/.vitepress/cache diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..82a2f13 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +ignore-workspace-root-check=true +git-checks=false diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..51eef02 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +docs/public/cw.js diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..7355b16 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d17c1c2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib", + "eslint.experimental.useFlatConfig": true, + "yaml.schemas": { + "./schema/config.schema.json": "/config.yaml" + } +} diff --git a/LICENSE b/LICENSE index 153d416..0a04128 100644 --- a/LICENSE +++ b/LICENSE @@ -162,4 +162,4 @@ General Public License ever published by the Free Software Foundation. whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the -Library. \ No newline at end of file +Library. diff --git a/README.md b/README.md index b499a70..adf81d8 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,23 @@ -# ClientWorker - -文档地址:[ClientWorker](https://clientworker.js.org) - -↑这也是用ClientWorker搭建的! - -## 它能干什么 - -- 绕备,在域名不变动的情况下,其余用户所有请求均可以定向到你的其他服务器或者cdn,而首屏域名无需ICP备案。 -- 降本,你可以用廉价的家宽+公网ipv4/ipv6,即使是80/443被封锁,你也可以在不变动端口的情况下将用户流量引向家宽。 -- 白嫖,可以用免费的公网穿透服务,接近零成本托管你的服务。 -- 加速,将静态资源流量(乃至动态资源)**并发**到全球cdn,实现前端级负载均衡。 -- 绕禁,通过在前端修改标头的方式,修复被故意篡改的`MIME`,正常托管网站,绕过各大托管商对于网站部署的限制,可以毫无负担的使用阿里云、腾讯云等对象存储而不用开启网站模式,乃至GithubRaw无限流量(绕过GithubPage 100GB限制)。 -- 愈合:通过并发方式,辅助JSDelivr、Unpkg、cdnjs等大陆几乎不可达请求重定向至其他cdn,从而实现无修改、全球加速。 -- 不宕,即使首屏服务器离线或不可达,已访问过的用户依旧可以正常命中备用服务器。 -- 缓存,颗粒化控制缓存,多种情况不同选择,智能调度缓存和请求,避免有缓存时无返回、缓存无法及时更新问题,确保缓存在客户端工作的更顺畅。 -- 离线,可以迅速支撑普通离线应用,助力快速构建PWA。 -- 兼容,Webp无缝,可以通过判断标头来判断是否支持Webp,并且自动替换图片请求,为网站加速助力。 -- 审核,通过内置的规则可以屏蔽并替换、拦截敏感词汇,实现网站内容安全。 -- 无刷,你不需要刷新就可以激活ClientWorker -- 热更,即使源站完全宕机,你也可以更新用户手中的ClientWorker与配置,确保网站正常运行。 -- 切片,对于一个请求发起多个切片以提高单文件下载速度 -- 叠速,专门为ClientWorker开发的`KFCThursdayVW50`引擎能在浏览器端切片并同时并发不同的镜像服务器,对于下载大文件可以带宽叠加的效果。 -- 均衡,对多个镜像并发,选择最优的镜像服务器,保证网站的响应速度,同时达到负载均衡的目的。 -- 高度自定义...更多玩法等你挖掘 - -## License - -GPL-3.0-or-later +# pkg-name + +[](https://www.npmjs.com/package/pkg-name) + +## 💎 Features + +## 📦 Installation + +```bash +$ npm install pkg-name +$ yarn add pkg-name +$ pnpm add pkg-name +``` + +## 🚀 Usage + +```ts + +``` + +## 📝 License + +[MIT](./LICENSE). Made with ❤️ by [Ray](https://github.com/so1ve) diff --git a/cw.config.js b/cw.config.js deleted file mode 100644 index 56d2949..0000000 --- a/cw.config.js +++ /dev/null @@ -1,22 +0,0 @@ -import path from 'path' -import { fileURLToPath } from 'url'; -import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; -import TerserPlugin from 'terser-webpack-plugin'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const development = 0 -export default { - entry: './main/entry.js', - optimization: { - minimize: !development, - minimizer: [ - new TerserPlugin({ - extractComments: false, - }), - ], - }, - output: { - path: path.resolve(__dirname, './dist'), - filename: 'cw.js', - } -} \ No newline at end of file diff --git a/doc/.gitignore b/doc/.gitignore deleted file mode 100644 index b512c09..0000000 --- a/doc/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/doc/docs/.vitepress/config.js b/doc/docs/.vitepress/config.js deleted file mode 100644 index f96634a..0000000 --- a/doc/docs/.vitepress/config.js +++ /dev/null @@ -1,87 +0,0 @@ -import cwpkgjson from './../../../package.json'; -export default { - title: 'ClientWorker', - description: '一个基于规则的前端路由拦截器', - lang: 'zh-CN', - - head: [ - //['link', { rel: 'icon', href: '/favicon.png' }], - ['meta', { name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi' }], - ['link', { href: 'https://npmm/lightgallery@2.3.0/css/lightgallery.css', rel: 'stylesheet' }], - ['script', { src: 'https://npmm/lightgallery@2.3.0/lightgallery.min.js' }], - ['script', { src: `https://npmm/clientworker@${cwpkgjson.version}/dist/autoupdate.js` }] - ], - - lastUpdated: true, - themeConfig: { - socialLinks: [ - { icon: 'github', link: 'https://github.com/ChenYFan/ClientWorker' } - ], - nav: [ - // NavbarItem - { - text: '首页', - link: '/', - }, - { - text: '规则', - link: '/rule/', - }, - { - text: '例子', - link: '/example/parallelcdn', - }, - { - text: '拓展', - link: '/ext/engine', - }, - { - text: 'Q群', - link: 'https://jq.qq.com/?_wv=1027&k=rAcnhzqK', - }, - { - text: '优秀配置', - link: 'https://github.com/ChenYFan/ClientWorker/discussions/categories/awesome-example' - } - ], - sidebar: [ - { - text: '上手', - items: [ - { text: '开始', link: '/start' } - ] - }, - { - text: '规则书写', - items: [ - { text: '捕捉与搜索 | Search & Catch', link: '/rule/' }, - { text: 'url重写/并发 | url replace/parallel', link: '/rule/replace' }, - { text: '重定向 | redirect', link: '/rule/redirect' }, - { text: '返回响应 | return', link: '/rule/return' }, - { text: '重写标头 | header', link: '/rule/header' }, - { text: '发起请求 | fetch', link: '/rule/fetch' }, - { text: '跳过处理 | skip', link: '/rule/skip' }, - { text: '自定义脚本 | script', link: '/rule/script' } - ] - }, - { - text: '例子', - items: [ - { text: '如何解决JSDelivr等cdn在境内加载缓慢问题', link: '/example/parallelcdn' }, - { text: 'WEBP兼容计划', link: '/example/autowebp' }, - { text: '如何自动更新配置和ClientWorker', link: '/example/autoupdate' }, - { text: '转发、并发、绕备', link: '/example/forward' } - ] - }, - { - text: '拓展', - items: [ - { text: '自动清理过期缓存', link: '/ext/autoclean' }, - { text: "热更新", link: "/ext/hotupdate" }, - { text: '关于引擎', link: '/ext/engine' }, - { text: "内置API接口", link: "/ext/api" } - ] - } - ] - } -} diff --git a/doc/docs/example/autoupdate.md b/doc/docs/example/autoupdate.md deleted file mode 100644 index 572fcd1..0000000 --- a/doc/docs/example/autoupdate.md +++ /dev/null @@ -1,41 +0,0 @@ -# 自动更新配置 - -ClientWorker外暴露了一个接口`/cw-cgi/api?type=config`,对其作任何请求即可更新配置,只要定时请求这个接口即可完成定时更新。 - -```js -async function updateConfig() { - await fetch('/cw-cgi/api?type=config').then(res => res.text()).then(res => { - if (res === 'ok') { - console.log(`Config updated`); - } else { - console.log(`Config update failed`); - } - }) - } -``` - -你也可以使用ClientWorker的`autoupdate.js`来实现更新。 - -# 更新ClientWorker - -重定向到ClientWorker安装页`/404`即可完成更新,当然更佳的选择是在你自己的网站上定时卸载并重新安装`/cw.js`。 - -```js -async function updateSW() { - if (navigator.serviceWorker) { - navigator.serviceWorker.getRegistrations().then(async registrations => { - for (let registration of registrations) { - await registration.update(); - } - console.log(`Unregistered service workers`); - }).then(() => { - navigator.serviceWorker.register('/cw.js').then(async registration => { - console.log(`Registered service worker`); - await registration.update(); - }) - }) - } - }; -``` - -你也可以使用ClientWorker的`autoupdate.js`来实现更新。 \ No newline at end of file diff --git a/doc/docs/example/forward.md b/doc/docs/example/forward.md deleted file mode 100644 index ce1ca72..0000000 --- a/doc/docs/example/forward.md +++ /dev/null @@ -1,81 +0,0 @@ -# 纯静态网站加速 - -你可以将你的网站放在对象存储等其他空间上作为镜像,然后使用以下配置: - -```yaml -catch_rules: #转换规则 - - rule: _ #ClientWorker语法糖,匹配当前域,返回一个域名带端口 - transform_rules: #转换规则,最上面的优先最高 - - search: \#.* #在发送请求时匹配#后内容并移除 - replace: '' - - search: \?.* #在发送请求时匹配?后内容并移除,仅限静态请求 - replace: '' - - search: _ - replace: - - _ #保留原始请求 - - xxx.github.io #GithubPage托管 - - xxx.gitee.io #GiteePage托管 - - unpkg.com/xxx-html@xxx.xxx/dist #NPM托管 - - cdnjs.cloudflare.com/ajax/libs/xxx/xxx.xxx/dist #CDNJS托管(大雾 - - examplebucket.oss-xx-xx.aliyuncs.com #阿里云对象存储托管 - - xxx.tencentcs.com #腾讯对象存储托管 - - xxx.qbox.me - - - search: \.html$ - header: - Content-Type: text/html;charset=UTF-8 #修复标头 - - - search: _ - action: fetch - fetch: - status: 200 - engine: classic - preflight: false - timeout: 5000 -``` - -**主站和分流站需要HTTPS,ClientWorker在HTTP环境下不工作** - -# ICP绕备、家宽、动态加速 - -```yaml -catch_rules: #转换规则 - - rule: _ #ClientWorker语法糖,匹配当前域,返回一个域名带端口 - transform_rules: #转换规则,最上面的优先最高 - - search: \#.* #在发送请求时匹配#后内容并移除 - replace: '' - - - search: _ - replace: - - _ #保留原始请求 - - 123.45.67.89 #ip镜像,需要ip HTTPS - - 123.45.67.90:12345 #任意端口 - - [2606::1234]:34567 #ipv6 - - 1.2.3.4.nip.io:65121 - - - search: \.(js|css) - action: fetch - fetch: - status: 200 - engine: classic - preflight: false - timeout: 5000 - mode: cors - redirect: follow - credentials: include - - - search: _ - action: fetch - fetch: - status: 200 - engine: parallel - preflight: true - mode: cors - redirect: follow - credentials: include - timeout: 5000 -``` - -**主站和分流站需要HTTPS,ClientWorker在HTTP环境下不工作** - -**此外,为了正确传递Ccookie等鉴权消息,`preflight`设为开,并且`credentials`为`include`,这意味着你的源站必须要开启`Access-Control-Allow-Origin`(不能为`*`,必须是当前域名)和`Access-Control-Allow-Credentials`为`true`,否则会直接失败** \ No newline at end of file diff --git a/doc/package.json b/doc/package.json deleted file mode 100644 index 870735c..0000000 --- a/doc/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "clientworker-doc", - "type": "commonjs", - "version": "0.0.0", - "main": "index.js", - "directories": { - "doc": "docs" - }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "docs:dev": "vitepress dev docs --host 0.0.0.0", - "docs:build": "vitepress build docs", - "docs:serve": "vitepress serve docs" - }, - "author": "", - "license": "ISC", - "description": "" -} diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js new file mode 100644 index 0000000..47ea35d --- /dev/null +++ b/docs/.vitepress/config.js @@ -0,0 +1,111 @@ +export default { + title: "ClientWorker", + description: "一个基于规则的前端路由拦截器", + lang: "zh-CN", + + head: [ + // ['link', { rel: 'icon', href: '/favicon.png' }], + [ + "meta", + { + name: "viewport", + content: + "width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi", + }, + ], + [ + "link", + { + href: "https://npmm/lightgallery@2.3.0/css/lightgallery.css", + rel: "stylesheet", + }, + ], + ["script", { src: "https://npmm/lightgallery@2.3.0/lightgallery.min.js" }], + [ + "script", + { + src: "/autoupdate.js", + }, + ], + ], + + lastUpdated: true, + themeConfig: { + socialLinks: [ + { icon: "github", link: "https://github.com/ChenYFan/ClientWorker" }, + ], + nav: [ + // NavbarItem + { + text: "首页", + link: "/", + }, + { + text: "规则", + link: "/rule/", + }, + { + text: "例子", + link: "/example/parallelcdn", + }, + { + text: "拓展", + link: "/ext/engine", + }, + { + text: "Q群", + link: "https://jq.qq.com/?_wv=1027&k=rAcnhzqK", + }, + { + text: "优秀配置", + link: "https://github.com/ChenYFan/ClientWorker/discussions/categories/awesome-example", + }, + ], + sidebar: [ + { + text: "上手", + items: [{ text: "开始", link: "/start" }], + }, + { + text: "规则书写", + items: [ + { text: "捕捉与搜索 | Search & Catch", link: "/rule/" }, + { + text: "url重写/并发 | url replace/parallel", + link: "/rule/replace", + }, + { text: "重定向 | redirect", link: "/rule/redirect" }, + { text: "返回响应 | return", link: "/rule/return" }, + { text: "重写标头 | header", link: "/rule/header" }, + { text: "发起请求 | fetch", link: "/rule/fetch" }, + { text: "跳过处理 | skip", link: "/rule/skip" }, + { text: "自定义脚本 | script", link: "/rule/script" }, + ], + }, + { + text: "例子", + items: [ + { + text: "如何解决JSDelivr等cdn在境内加载缓慢问题", + link: "/example/parallelcdn", + }, + { text: "WEBP兼容计划", link: "/example/autowebp" }, + { + text: "如何自动更新配置和ClientWorker", + link: "/example/autoupdate", + }, + { text: "转发、并发、绕备", link: "/example/forward" }, + ], + }, + { + text: "拓展", + items: [ + { text: "自动清理过期缓存", link: "/ext/autoclean" }, + { text: "热更新", link: "/ext/hotupdate" }, + { text: "关于引擎", link: "/ext/engine" }, + { text: "内置API接口", link: "/ext/api" }, + ], + }, + ], + }, +}; diff --git a/docs/example/autoupdate.md b/docs/example/autoupdate.md new file mode 100644 index 0000000..4dcf18b --- /dev/null +++ b/docs/example/autoupdate.md @@ -0,0 +1,48 @@ +# 自动更新配置 + +ClientWorker外暴露了一个接口`/cw-cgi/api?type=config`,对其作任何请求即可更新配置,只要定时请求这个接口即可完成定时更新。 + +```js +async function updateConfig() { + await fetch("/cw-cgi/api?type=config") + .then((res) => res.text()) + .then((res) => { + if (res === "ok") { + console.log("Config updated"); + } else { + console.log("Config update failed"); + } + }); +} +``` + +你也可以使用ClientWorker的`autoupdate.js`来实现更新。 + +# 更新ClientWorker + +重定向到ClientWorker安装页`/404`即可完成更新,当然更佳的选择是在你自己的网站上定时卸载并重新安装`/cw.js`。 + +```js +async function updateSW() { + if (navigator.serviceWorker) { + navigator.serviceWorker + .getRegistrations() + .then(async (registrations) => { + for (const registration of registrations) { + await registration.update(); + } + console.log("Unregistered service workers"); + }) + .then(() => { + navigator.serviceWorker + .register("/cw.js") + .then(async (registration) => { + console.log("Registered service worker"); + await registration.update(); + }); + }); + } +} +``` + +你也可以使用ClientWorker的`autoupdate.js`来实现更新。 diff --git a/doc/docs/example/autowebp.md b/docs/example/autowebp.md similarity index 99% rename from doc/docs/example/autowebp.md rename to docs/example/autowebp.md index 7c56adf..51197e7 100644 --- a/doc/docs/example/autowebp.md +++ b/docs/example/autowebp.md @@ -19,4 +19,4 @@ 这是一张jpg图片,当你浏览器支持Webp时,会替换到`webp`并显示`Webp Accept!`;当浏览器不支持Webp时,会显示`Webp Reject!This is a jpg file`。 - \ No newline at end of file + diff --git a/docs/example/forward.md b/docs/example/forward.md new file mode 100644 index 0000000..53f78ff --- /dev/null +++ b/docs/example/forward.md @@ -0,0 +1,81 @@ +# 纯静态网站加速 + +你可以将你的网站放在对象存储等其他空间上作为镜像,然后使用以下配置: + +```yaml +catch_rules: #转换规则 + - rule: _ #ClientWorker语法糖,匹配当前域,返回一个域名带端口 + transform_rules: #转换规则,最上面的优先最高 + - search: \#.* #在发送请求时匹配#后内容并移除 + replace: "" + - search: \?.* #在发送请求时匹配?后内容并移除,仅限静态请求 + replace: "" + - search: _ + replace: + - _ #保留原始请求 + - xxx.github.io #GithubPage托管 + - xxx.gitee.io #GiteePage托管 + - unpkg.com/xxx-html@xxx.xxx/dist #NPM托管 + - cdnjs.cloudflare.com/ajax/libs/xxx/xxx.xxx/dist #CDNJS托管(大雾 + - examplebucket.oss-xx-xx.aliyuncs.com #阿里云对象存储托管 + - xxx.tencentcs.com #腾讯对象存储托管 + - xxx.qbox.me + + - search: \.html$ + header: + Content-Type: text/html;charset=UTF-8 #修复标头 + + - search: _ + action: fetch + fetch: + status: 200 + engine: classic + preflight: false + timeout: 5000 +``` + +**主站和分流站需要HTTPS,ClientWorker在HTTP环境下不工作** + +# ICP绕备、家宽、动态加速 + +```yaml +catch_rules: #转换规则 + - rule: _ #ClientWorker语法糖,匹配当前域,返回一个域名带端口 + transform_rules: #转换规则,最上面的优先最高 + - search: \#.* #在发送请求时匹配#后内容并移除 + replace: "" + + - search: _ + replace: + - _ #保留原始请求 + - 123.45.67.89 #ip镜像,需要ip HTTPS + - 123.45.67.90:12345 #任意端口 + - \[2606::1234]:34567 #ipv6 + - 1.2.3.4.nip.io:65121 + + - search: \.(js|css) + action: fetch + fetch: + status: 200 + engine: classic + preflight: false + timeout: 5000 + mode: cors + redirect: follow + credentials: include + + - search: _ + action: fetch + fetch: + status: 200 + engine: parallel + preflight: true + mode: cors + redirect: follow + credentials: include + timeout: 5000 +``` + +**主站和分流站需要HTTPS,ClientWorker在HTTP环境下不工作** + +**此外,为了正确传递Ccookie等鉴权消息,`preflight`设为开,并且`credentials`为`include`,这意味着你的源站必须要开启`Access-Control-Allow-Origin`(不能为`*`,必须是当前域名)和`Access-Control-Allow-Credentials`为`true`,否则会直接失败** diff --git a/doc/docs/example/parallelcdn.md b/docs/example/parallelcdn.md similarity index 99% rename from doc/docs/example/parallelcdn.md rename to docs/example/parallelcdn.md index 4537241..11bf9fc 100644 --- a/doc/docs/example/parallelcdn.md +++ b/docs/example/parallelcdn.md @@ -39,7 +39,6 @@ NPM的镜像相对较少,如果有更多的推荐可以点击右上角Github - https://cdn.staticfile.org - https://mirrors.sustech.edu.cn/cdnjs/ajax/libs # 南大 - https://cdnjs.sourcegcdn.com/ajax/libs # 全同步 https://cdnjs.cloudflare.com - ``` ## `Github` diff --git a/doc/docs/ext/api.md b/docs/ext/api.md similarity index 97% rename from doc/docs/ext/api.md rename to docs/ext/api.md index 8920191..362a348 100644 --- a/doc/docs/ext/api.md +++ b/docs/ext/api.md @@ -6,7 +6,7 @@ ClientWorker默认会劫持`/cw-cgi/`作为前端控制台响应,也提供了 这是API类型: -## `config` +## `config` > 任何请求方式均可 @@ -32,4 +32,4 @@ ClientWorker默认会劫持`/cw-cgi/`作为前端控制台响应,也提供了 ## `version` -返回版本号,这也是指示ClientWorker安装成功的表现。 \ No newline at end of file +返回版本号,这也是指示ClientWorker安装成功的表现。 diff --git a/doc/docs/ext/autoclean.md b/docs/ext/autoclean.md similarity index 87% rename from doc/docs/ext/autoclean.md rename to docs/ext/autoclean.md index 7ca50f9..d838864 100644 --- a/doc/docs/ext/autoclean.md +++ b/docs/ext/autoclean.md @@ -1,4 +1,4 @@ -# 过期缓存自动清除 +# 过期缓存自动清除 ClientWorker内置了一个定时器,在每次启动时被激活,用于循环定时检测并删除过期缓存。 @@ -9,4 +9,4 @@ name: ClientWorker Docs Config cleaninterval: 1000*20 # 每20秒检测并清理一次 ``` -> ClientWorker在依赖的页面被关闭时会存活大约1分钟。被ClientWorker被杀死后过期的缓存不会被清理。直到下一次激活才会重新清理。 \ No newline at end of file +> ClientWorker在依赖的页面被关闭时会存活大约1分钟。被ClientWorker被杀死后过期的缓存不会被清理。直到下一次激活才会重新清理。 diff --git a/doc/docs/ext/engine.md b/docs/ext/engine.md similarity index 97% rename from doc/docs/ext/engine.md rename to docs/ext/engine.md index 79b779d..dfd5c0e 100644 --- a/doc/docs/ext/engine.md +++ b/docs/ext/engine.md @@ -8,8 +8,7 @@ ClientWorker中拥有五款原理不同的并发引擎,他们分别是`fetch` 在这其中,`fetch`(JS原始请求方式) 与 `Crazy`是单请求输入引擎,`Classic` 、 `Parallel` 与 `KFCThursdayVW50` 是多请求输入引擎。这意味着后面两个引擎可以同时对多个地址发起请求,而前面两个引擎只能对单个地址发起请求。请注意,除了`fetch` 之外,其他引擎都是**多线程的**,非多线程请求将会被降级。 -> **注意:** -> `fetch` `Crazy` 只接受字符串形式的url +> **注意:** > `fetch` `Crazy` 只接受字符串形式的url > `Classic` `Parallel` `KFCThursdayVW50` 只接受数组形式的urls `Promise.any`的兼容性远低于`ServiceWorker`,ClientWorker会自动对其PolyFill,因此ClientWorker兼容性最低要求与ServiceWorker相同。 @@ -72,7 +71,7 @@ ClientWorker中拥有五款原理不同的并发引擎,他们分别是`fetch` 此后`KFCThursdayVW50`将**对每一个源**发起共`线程数`个大小为`总大小÷线程数`的请求,并发下载,在任何一个源响应正确代码后打断当前组的其余请求,最后合并为一个响应主体,并将`PreFetch`中的标头与状态还原。 -> 并发的总请求为线程数*源个数 +> 并发的总请求为线程数\*源个数 这种方式可以叠加不同镜像的带宽,适合下载较大的文件。 @@ -80,4 +79,4 @@ ClientWorker中拥有五款原理不同的并发引擎,他们分别是`fetch` > 对于较小的文件会起到**减速的效果** -> (4线程,4镜像)对于一个存储在Sharepoint的2GB文件,可以显著提速近7倍速度(30MB/s->200MB/s) \ No newline at end of file +> (4线程,4镜像)对于一个存储在Sharepoint的2GB文件,可以显著提速近7倍速度(30MB/s->200MB/s) diff --git a/doc/docs/ext/hotupdate.md b/docs/ext/hotupdate.md similarity index 78% rename from doc/docs/ext/hotupdate.md rename to docs/ext/hotupdate.md index f475efc..e544228 100644 --- a/doc/docs/ext/hotupdate.md +++ b/docs/ext/hotupdate.md @@ -13,8 +13,8 @@ ClientWorker支持从外部加载和更新ClientWorker及其配置,避免在 ```yaml name: ClientWorker hotpatch: - - https://raw.githubusercontent.com/ChenYFan/ClientWorker/gh-pages/cw.js - - https://cdn.jsdelivr.net/gh/ChenYFan/ClientWorker/cw.js + - https://raw.githubusercontent.com/ChenYFan/ClientWorker/gh-pages/cw.js + - https://cdn.jsdelivr.net/gh/ChenYFan/ClientWorker/cw.js ``` api请求请见[热更新 - ClientWorker热补丁](/ext/api.html)。 @@ -30,8 +30,8 @@ api请求请见[热更新 - ClientWorker热补丁](/ext/api.html)。 ```yaml name: ClientWorker hotconfig: - - https://raw.githubusercontent.com/ChenYFan/ClientWorker/gh-pages/config.yaml - - https://cdn.jsdelivr.net/gh/ChenYFan/ClientWorker/config.yaml + - https://raw.githubusercontent.com/ChenYFan/ClientWorker/gh-pages/config.yaml + - https://cdn.jsdelivr.net/gh/ChenYFan/ClientWorker/config.yaml ``` api请求请见[热更新 - Config热更新](/ext/api.html)。 diff --git a/doc/docs/index.md b/docs/index.md similarity index 99% rename from doc/docs/index.md rename to docs/index.md index 4fac840..cbdc38f 100644 --- a/doc/docs/index.md +++ b/docs/index.md @@ -28,4 +28,3 @@ features: title: 内置四套先进的请求引擎,满足你的需求 details: 自带Classic、Parallel、Crazy与KFCThursdayVW50四套并发引擎,完美解决前端请求故障,节省流量,负载均衡,加速下载,提高体验。 --- - diff --git a/docs/public/404.html b/docs/public/404.html new file mode 100644 index 0000000..2a14954 --- /dev/null +++ b/docs/public/404.html @@ -0,0 +1,336 @@ + + +
+ClientWorker正在启动
+ClientWorker正在启动
-