From 3efd4d404777a18d6c75c947370bbe8cf8115a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Tue, 26 Mar 2024 10:28:49 +0800 Subject: [PATCH] =?UTF-8?q?optimize:=20github=E6=8B=A6=E6=88=AA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=EF=BC=8C`*.fastgit.org`=20=E6=9B=B4=E6=8D=A2?= =?UTF-8?q?=E4=B8=BA=20`gh.api.99988866.xyz/https://github.com`=EF=BC=8C?= =?UTF-8?q?=E5=9B=A0=E4=B8=BA=20`*.fastgit.org`=20=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/config.js | 6 +++--- packages/core/src/config/index.js | 12 +++--------- packages/core/src/modules/server/index.js | 9 +++++++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/core/src/config.js b/packages/core/src/config.js index 00f66f1..c544f47 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -17,12 +17,12 @@ function get () { const getDefaultConfigBasePath = function () { return get().server.setting.userBasePath } -function _getRemoteSavePath (prefix = '', version = '') { +function _getRemoteSavePath (prefix = '') { const dir = getDefaultConfigBasePath() if (!fs.existsSync(dir)) { fs.mkdirSync(dir) } - return path.join(dir, prefix + 'remote_config.json' + version) + return path.join(dir, prefix + 'remote_config.json5') } function _getConfigPath () { const dir = getDefaultConfigBasePath() @@ -64,7 +64,7 @@ const configApi = { return } if (response && response.statusCode === 200) { - const originalRemoteSavePath = _getRemoteSavePath('original_', '5') + const originalRemoteSavePath = _getRemoteSavePath('original_') fs.writeFileSync(originalRemoteSavePath, body) log.info('保存原来的远程配置文件成功:', originalRemoteSavePath) diff --git a/packages/core/src/config/index.js b/packages/core/src/config/index.js index a4b2d44..8a7bd77 100644 --- a/packages/core/src/config/index.js +++ b/packages/core/src/config/index.js @@ -52,14 +52,14 @@ module.exports = { intercepts: { 'github.com': { '/.*/.*/releases/download/': { - redirect: 'download.fastgit.org', + redirect: 'gh.api.99988866.xyz/https://github.com', desc: 'release文件加速下载跳转地址' }, '/.*/.*/archive/': { - redirect: 'download.fastgit.org' + redirect: 'gh.api.99988866.xyz/https://github.com' }, '/.*/.*/blame/': { - redirect: 'hub.fastgit.org' + redirect: 'gh.api.99988866.xyz/https://github.com' }, '^/[^/]+/[^/]+(/releases(/.*)?)?$': { script: [ @@ -69,15 +69,9 @@ module.exports = { }, '/.*': { proxy: 'github.com', - // proxy: 'gh.docmirror.top/_proxy', desc: '目前禁掉sni就可以直接访问,如果后续github.com的ip被封锁,只能再走proxy模式', sni: 'baidu.com' } - // '/.*/.*/raw11/': { - // replace: '(.+)\\/raw\\/(.+)', - // proxy: 'raw.fastgit.org$1/$2', - // sni: 'baidu.com' - // } }, 'github-releases.githubusercontent.com': { '.*': { diff --git a/packages/core/src/modules/server/index.js b/packages/core/src/modules/server/index.js index d514ef6..18cc11e 100644 --- a/packages/core/src/modules/server/index.js +++ b/packages/core/src/modules/server/index.js @@ -67,6 +67,11 @@ const serverApi = { } } serverConfig.plugin = allConfig.plugin + + if (allConfig.proxy && allConfig.proxy.enabled) { + serverConfig.proxy = allConfig.proxy + } + // fireStatus('ing') // 启动中 const basePath = serverConfig.setting.userBasePath const runningConfigPath = path.join(basePath, '/running.json') @@ -125,13 +130,13 @@ const serverApi = { // fireStatus('ing')// 关闭中 server.close((err) => { if (err) { - log.info('close error', err, ',', err.code, ',', err.message, ',', err.errno) + log.warn('close error', err, ',', err.code, ',', err.message, ',', err.errno) if (err.code === 'ERR_SERVER_NOT_RUNNING') { log.info('代理服务关闭成功') resolve() return } - log.info('代理服务关闭失败', err) + log.warn('代理服务关闭失败', err) reject(err) } else { log.info('代理服务关闭成功')