Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

[bug] 302定向导致网页无法访问 #20

Open
YiHui-Liu opened this issue Aug 1, 2024 · 0 comments
Open

[bug] 302定向导致网页无法访问 #20

YiHui-Liu opened this issue Aug 1, 2024 · 0 comments

Comments

@YiHui-Liu
Copy link

(Hexo+Butterfly)访问部分子目录时,会由于302重定向错误:

The FetchEvent for "http://localhost:4000/s/about" resulted in a network error response: a redirected response was used for a request whose redirect mode is not "follow".

配置如下:

name: Fox-Client-Worker
catch_rules:
  - rule: _
    transform_rules:
      - search: \#.+
        searchin: url
        replace: ''
      - search: _
        action: fetch
        fetch:
          engine: fetch
      - search: (^4|^5)
        searchin: status
        action: return
        return:
          body: The GateWay is down!This Page is provided by ClientWorker!
          status: 503
  - rule: ^https\:\/\/((cdn|fastly|gcore|test1|quantil)\.jsdelivr\.net\/npm|unpkg\.com)
    transform_rules:
      - search: _
        replace:
          - _
          - https://unpkg.zhimg.com #回源已关闭,原缓存有效
          - https://npm.elemecdn.com #2022/7/12 确认关闭回源,缓存有效
          - https://code.bdstatic.com/npm #确认关闭回源,缓存有效
          - https://npm.sourcegcdn.com #滥用封仓库,强制数字版本号
          - https://cdn.bilicdn.tk/npm # 由GamerNoTitle提供的反代,请勿滥用:D
  - rule: ^https\:\/\/cdnjs\.cloudflare\.com\/ajax\/libs
    transform_rules:
      - search: _
        replace:
          - _
          - https://cdn.bootcdn.net/ajax/libs
          - https://lib.baomitu.com
          - https://mirrors.cqupt.edu.cn/cdnjs/ajax/libs # 重庆邮电
          - https://cdn.staticfile.org
          - https://mirrors.sustech.edu.cn/cdnjs/ajax/libs # 南大
          - https://cdnjs.sourcegcdn.com/ajax/libs # 全同步 https://cdnjs.cloudflare.com
if (!!navigator.serviceWorker) {
    if (localStorage.getItem('cw_installed') !== 'true') {window.stop();}
    navigator.serviceWorker.register('/cw.js?t=' + new Date().getTime()).then(async (registration) => {
        if (localStorage.getItem('cw_installed') !== 'true') {
            const conf = () => {
                console.log('[CW] Installing Success,Configuring...');
                fetch('/cw-cgi/api?type=config')
                    .then(res => res.text())
                    .then(text => {
                        if (text === 'ok') {
                            console.log('[CW] Installing Success,Configuring Success,Starting...');
                            localStorage.setItem('cw_installed', 'true');
                            window.location.reload();
                        } else {
                            console.warn('[CW] Installing Success,Configuring Failed,Sleeping 200ms...');
                            setTimeout(() => {
                                conf()
                            }, 200);
                        }
                    }).catch(err => {
                        console.log('[CW] Installing Success,Configuring Error,Exiting...');
                    });
            }
            setTimeout(() => {
                conf()
            }, 50);
        }
    }).catch(err => {
        console.error('[CW] Installing Failed,Error: ' + err.message);
    })
} else { console.error('[CW] Installing Failed,Error: Browser not support service worker'); }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant