0.2.2 onlyoffice修复

This commit is contained in:
liaibo
2026-01-17 12:38:04 +08:00
parent 19907bccdc
commit df2e9f5339
10 changed files with 349 additions and 893 deletions
@@ -150,7 +150,14 @@ const setupOnlyOfficeInternalRequestRewrite = (baseUrl: string, onlyofficeBaseUr
return `${window.location.origin.replace(/\/+$/, "")}${normalizedBase}`;
})();
const internalOrigins = new Set<string>(["http://127.0.0.1:8081", "http://localhost:8081"]);
const internalOrigins = new Set<string>([
"http://127.0.0.1:8081",
"http://localhost:8081",
// 说明:部分环境下 ONLYOFFICE 会错误拼出 https://127.0.0.1:8081 这类 URL
// 浏览器会报 ERR_SSL_PROTOCOL_ERROR(因为 8081 实际是 http)。这里也一起兜底重写。
"https://127.0.0.1:8081",
"https://localhost:8081",
]);
try {
if (onlyofficeBaseUrlDesktop) {
const u = new URL(onlyofficeBaseUrlDesktop);
@@ -166,6 +173,19 @@ const setupOnlyOfficeInternalRequestRewrite = (baseUrl: string, onlyofficeBaseUr
const rewriteUrl = (input: string) => {
try {
const u = new (win as any).URL(input, (win as any).location?.origin || window.location.origin);
// 说明:外网 https 访问时,若 ONLYOFFICE 错误生成 http://<host>/onlyoffice-server/... 会被 Mixed Content 阻止;
// 这里提前升级为 https,避免浏览器直接拦截请求。
try {
const loc = (win as any).location;
if (loc?.protocol === "https:" && u.protocol === "http:" && u.host === loc.host) {
if (u.pathname === "/onlyoffice-server" || u.pathname.startsWith("/onlyoffice-server/")) {
u.protocol = "https:";
return u.toString();
}
}
} catch {
// ignore
}
const origin = `${u.protocol}//${u.host}`;
if (!internalOrigins.has(origin)) return input;
return `${proxyPrefix}${u.pathname}${u.search}${u.hash}`;