reverse proxy info

This commit is contained in:
Mateusz Gruszczyński
2026-07-24 13:39:40 +02:00
parent 21800b9bcb
commit 2c46314425
4 changed files with 37 additions and 3 deletions
+23
View File
@@ -1,6 +1,26 @@
import { logDebug, logError, logWarn } from "./logger.js";
function formatBytes(bytes) {
if (bytes >= 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(bytes % (1024 * 1024) ? 1 : 0)} MB`;
if (bytes >= 1024) return `${Math.ceil(bytes / 1024)} KB`;
return `${bytes} B`;
}
function validateUploadSize(body) {
if (!(body instanceof FormData)) return;
const maxBytes = Number(window.__RUSTPAD_CONFIG__?.uploadMaxSizeBytes || 0);
if (!Number.isFinite(maxBytes) || maxBytes <= 0) return;
for (const value of body.values()) {
if (value instanceof File && value.size > maxBytes) {
const error = new Error(`The selected file is ${formatBytes(value.size)}. The upload limit is ${formatBytes(maxBytes)}.`);
error.status = 413;
throw error;
}
}
}
export async function api(path, options = {}) {
validateUploadSize(options.body);
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 12000);
try {
@@ -24,6 +44,9 @@ export async function api(path, options = {}) {
} catch (error) {
if (error.name === "AbortError") { logWarn("api.timeout", { method: options.method || "GET", path }); throw new Error("Timed out"); }
logError("api.network_error", error, { method: options.method || "GET", path });
if (options.body instanceof FormData && error instanceof TypeError) {
throw new Error("Upload failed before the server returned a response. The file may exceed the server or proxy upload limit.");
}
throw error;
} finally { clearTimeout(timeout); }
}
+5 -1
View File
@@ -53,7 +53,11 @@ export function applyFormat(editor, format) {
if (format === "codeblock-lines") toggleWrap(editor, "```text=\n", "\n```", "code");
if (format === "mermaid") toggleWrap(editor, "```mermaid\n", "\n```", "graph TD\n A[Start] --> B[End]");
if (format === "details") toggleWrap(editor, "<details>\n<summary>Click me</summary>\n\n", "\n</details>", "Content");
if (format === "toc") toggleWrap(editor, "", "", "[TOC]");
if (format === "toc") {
const { start, end } = selection(editor);
const selected = editor.value.slice(start, end);
editor.setRangeText(selected || "[TOC]", start, end, selected ? "select" : "end");
}
if (format.startsWith("alert-")) {
const type = format.slice("alert-".length);
toggleWrap(editor, `:::${type}\n`, "\n:::", "Alert content");