fix(config): улучшить обработку URL для бэкенда и увеличить таймаут запросов
Docker images / prepare-release (push) Successful in 6s
Docker images / backend-image (push) Successful in 1m36s
Docker images / frontend-image (push) Successful in 1m39s
Docker images / updater-image (push) Successful in 50s
Docker images / notify-webhook (push) Has been skipped
Docker images / publish-release (push) Successful in 8s

This commit is contained in:
Denozordec
2026-05-12 23:19:51 +07:00
parent 158fc36294
commit 399871f4f9
8 changed files with 83 additions and 10 deletions
+13
View File
@@ -0,0 +1,13 @@
import type { NextRequest } from "next/server"
import { proxyBackendRequest } from "@/lib/proxy-backend-request"
export const runtime = "nodejs"
export const dynamic = "force-dynamic"
export const maxDuration = 600
export async function GET(request: NextRequest) {
return proxyBackendRequest(request, "/api/system/database/backup", {
method: "GET",
forwardRequestBody: false,
})
}
+10
View File
@@ -0,0 +1,10 @@
import type { NextRequest } from "next/server"
import { proxyBackendRequest } from "@/lib/proxy-backend-request"
export const runtime = "nodejs"
export const dynamic = "force-dynamic"
export const maxDuration = 600
export async function POST(request: NextRequest) {
return proxyBackendRequest(request, "/api/system/database/restore", { method: "POST" })
}
+1
View File
@@ -28,6 +28,7 @@ import { refreshScheduler, stopScheduler } from "./services/scheduler.js"
const app = Fastify({
bodyLimit: 512 * 1024 * 1024,
requestTimeout: 10 * 60 * 1000,
logger: {
transport: {
target: "pino-pretty",
+3
View File
@@ -0,0 +1,3 @@
export function backendInternalUrl(): string {
return (process.env.BACKEND_INTERNAL_URL ?? "http://127.0.0.1:8000").replace(/\/$/, "")
}
+50
View File
@@ -0,0 +1,50 @@
import type { NextRequest } from "next/server"
import { backendInternalUrl } from "@/lib/backend-internal-url"
type ProxyBackendRequestOptions = {
method?: string
forwardRequestBody?: boolean
}
export async function proxyBackendRequest(
request: NextRequest,
backendPath: string,
options: ProxyBackendRequestOptions = {},
): Promise<Response> {
const method = options.method ?? request.method
const headers = new Headers()
for (const [key, value] of request.headers.entries()) {
const lower = key.toLowerCase()
if (lower === "host" || lower === "connection") continue
headers.set(key, value)
}
const fetchInit: RequestInit & { duplex?: "half" } = {
method,
headers,
cache: "no-store",
}
const forwardRequestBody = options.forwardRequestBody ?? !["GET", "HEAD"].includes(method)
if (forwardRequestBody && request.body) {
fetchInit.body = request.body
fetchInit.duplex = "half"
}
try {
const upstream = await fetch(`${backendInternalUrl()}${backendPath}`, fetchInit)
const responseHeaders = new Headers()
const contentType = upstream.headers.get("Content-Type")
const contentDisposition = upstream.headers.get("Content-Disposition")
if (contentType) responseHeaders.set("Content-Type", contentType)
if (contentDisposition) responseHeaders.set("Content-Disposition", contentDisposition)
return new Response(upstream.body, {
status: upstream.status,
headers: responseHeaders,
})
} catch (error) {
const message = error instanceof Error ? error.message : "Не удалось связаться с бекендом"
return Response.json({ error: message }, { status: 502 })
}
}
+4 -7
View File
@@ -1,9 +1,5 @@
import type { NextConfig } from "next";
const backendInternalUrl = (process.env.BACKEND_INTERNAL_URL ?? "http://127.0.0.1:8000").replace(
/\/$/,
"",
);
import { backendInternalUrl } from "./lib/backend-internal-url";
const nextConfig: NextConfig = {
output: "standalone",
@@ -11,9 +7,10 @@ const nextConfig: NextConfig = {
proxyClientMaxBodySize: "512mb",
},
async rewrites() {
const backendUrl = backendInternalUrl();
return [
{ source: "/health", destination: `${backendInternalUrl}/health` },
{ source: "/api/:path*", destination: `${backendInternalUrl}/api/:path*` },
{ source: "/health", destination: `${backendUrl}/health` },
{ source: "/api/:path*", destination: `${backendUrl}/api/:path*` },
];
},
};
+1 -2
View File
@@ -56,11 +56,10 @@ export async function restoreSystemDatabaseBackup(baseUrl: string, file: File):
413,
)
}
const body = await file.arrayBuffer()
const res = await fetch(resolveDatabaseApiUrl(baseUrl, "/api/system/database/restore"), {
method: "POST",
headers: { "Content-Type": "application/octet-stream" },
body,
body: file,
})
if (!res.ok) {
const payload = await res.json().catch(() => undefined)
+1 -1
View File
File diff suppressed because one or more lines are too long