feat(static): fetch index.html from cdn for beta#372
Merged
PIKACHUIM merged 8 commits intoOpenListTeam:mainfrom Jul 22, 2025
Merged
feat(static): fetch index.html from cdn for beta#372PIKACHUIM merged 8 commits intoOpenListTeam:mainfrom
PIKACHUIM merged 8 commits intoOpenListTeam:mainfrom
Conversation
Member
|
同意第一点,第二点经商议未得出结论, 要不让大佬看看 @KirCute |
Contributor
|
Beta 版本不应该用于生产吧,其次 需要考虑网络受限的环境 |
Member
Author
正常情况是这样,但还是有特殊情况,需要用到Beta 版本、自行构建的 Beta 版本中的功能,因此有需求给 Beta 版本上 CDN。 解释一下:
为什么不使用程序内置的 因为 ...
var preloads = [
{
parentTagName: "head",
tagName: "link",
attrs: { href: "/static/manifest.json", rel: "manifest" },
},
{
parentTagName: "head",
tagName: "script",
attrs: {
type: "module",
crossorigin: "",
src: "/assets/index-fec7825c.js",
},
},
{
parentTagName: "head",
tagName: "link",
attrs: { rel: "stylesheet", href: "/assets/index-c0564af7.css" },
},
];
...让这个文件名后面的哈希消失,也可以解决问题,但也会出现
如果部署 OpenList 的机器网络受限,可以选择不用 CDN ——不要定义 如果配置的 CDN 是网络受限的,那我认为也没折腾的必要。而且作为 Beta 版本,正如您说的,不应该在生产中使用。 如果社区对于此 PR 的第 2 点持否定态度,请务必让我知道,我会将本 PR 的第 1 点单独提取出来,谢谢! |
Member
Author
Member
Author
|
以下是 Mermaid 便于理解: flowchart TD
A[程序初始化] --> B{是否配置CDN?}
B -->|是| D{版本类型?}
B -->|否| E{是否配置本地dist?}
E -->|否| F[使用程序内置的index.html]
E -->|是| G[使用本地dist中的index.html]
D -->|Beta版本| H[从CDN获取index.html]
D -->|Release版本| F
H --> I{CDN获取成功?}
I -->|成功| J[使用CDN获取的index.html]
I -->|失败| K[Resty重试3次]
K -->|成功| J
K -->|仍失败| L[程序退出,等待重启]
F --> M[替换CDN、站点信息等变量]
G --> M
J --> M
M --> N[返回页面]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

目前 OpenList 使用 CDN 部署存在以下问题和优化:
1. 本地资源与 CDN 资源未隔离
当
config.json中配置了 CDN 域名后,前端静态资源仍可通过本地路径访问。由于 OpenList 引入 SWF 播放器后前端应用体积翻倍,存在一些 WASM 的大文件,这可能被恶意刷取流量,消耗源站带宽资源。本 PR b5d685d 已修复该问题,在配置了 CDN 的条件下禁止添加本地资源的路由,实现了 CDN 与本地资源的访问隔离。
2.
index.html文件版本不兼容目前前端 Vite 打包生成的 JS 文件名采用哈希命名,修改过的部分构建后文件名会发生变化,导致不同版本的
index.html彼此不兼容。OpenList 的
index.html需要加载到本地内存中,因为后端还会插入一些代码、修改变量等等,仅使用 Pages 修改 API 地址部署会导致功能缺失、路由失效。embed.FS中的index.html,一般不会出现问题;index.html,因此不受太大的影响;index.html文件,并配置 CDN。index.html,配置 CDN 后易出现资源路径失效的问题。为解决 Beta 版本的 CDN 资源适配问题,本 PR 实现了从 CDN 获取
index.html的功能,可以参考以下步骤实现:index.html不是最新的,也不影响使用。config.json中配置 CDN;index.html;