This commit is contained in:
user 2025-09-25 12:19:06 +03:00
parent c8b121fb16
commit a837eb2d3e
3 changed files with 43 additions and 11 deletions

View File

@ -82,6 +82,8 @@ services:
- TUSD_LOG_LEVEL=info
volumes:
- ${TUSD_DATA_DIR_HOST:-./data/tusd}:/data
ports:
- "${TUSD_HTTP_PORT:-13400}:1080"
depends_on:
backend-app:
condition: service_started

View File

@ -8,6 +8,11 @@ upstream frontend_web {
keepalive 16;
}
upstream tusd_backend {
server 127.0.0.1:13400;
keepalive 16;
}
# Access log format including request id
log_format reqid '$time_iso8601 [$req_id] $remote_addr "$request" $status $body_bytes_sent $request_time "$http_referer" "$http_user_agent"';
@ -69,9 +74,6 @@ server {
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PATCH, HEAD" always;
add_header Access-Control-Allow-Headers "Origin, Cache-Control, Content-Type, Accept, Authorization, Referer, User-Agent, Sec-Fetch-Dest, Sec-Fetch-Mode, Sec-Fetch-Site, Tus-Resumable, tus-resumable, Upload-Length, upload-length, Upload-Offset, upload-offset, Upload-Metadata, upload-metadata, Upload-Defer-Length, upload-defer-length, Upload-Concat, upload-concat, x-file-name, x-last-chunk, x-chunk-start, x-upload-id, x-request-id" always;
# Быстрая обработка preflight (если бэкенд недоступен)
if ($request_method = OPTIONS) { return 204; }
# Статика фронтенда (SPA)
location / {
proxy_pass http://frontend_web;
@ -100,6 +102,30 @@ server {
add_header Cache-Control "public, max-age=31536000, immutable" always;
}
location = /tus {
return 308 /tus/;
}
location /tus/ {
# Proxy uploads to tusd with resumable-friendly settings
proxy_pass http://tusd_backend/;
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;
proxy_max_temp_file_size 0;
proxy_redirect off;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Request-Id $req_id;
add_header Access-Control-Expose-Headers "Location, Upload-Offset, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension" always;
}
# API
location /api/ {
proxy_pass http://backend_app;
@ -124,6 +150,8 @@ server {
# Вебсокеты (на будущее)
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
if ($request_method = OPTIONS) { return 204; }
}
# Health to backend

View File

@ -170,6 +170,8 @@ update_env DATABASE_URL "postgresql+psycopg2://${pg_user}:${pg_pass}@${pg_host}:
ensure_env_default FRONTEND_HTTP_PORT "13300"
ensure_env_default VITE_SENTRY_DSN ""
ensure_env_default TUSD_HTTP_PORT "13400"
tusd_port=$(ini_val TUSD_HTTP_PORT)
current_api_base=$(ini_val VITE_API_BASE_URL)
if [[ -z "$current_api_base" || "$current_api_base" == "https://my-public-node-8.projscale.dev/api/v1" ]]; then
if [[ -n "${PUBLIC_HOST:-}" ]]; then
@ -187,6 +189,14 @@ if [[ -z "$current_api_storage" || "$current_api_storage" == "https://my-public-
update_env VITE_API_BASE_STORAGE_URL "http://127.0.0.1:${BACKEND_HTTP_PORT}/api/v1.5/storage"
fi
fi
current_tus_endpoint=$(ini_val VITE_TUS_ENDPOINT)
if [[ -n "${PUBLIC_HOST:-}" ]]; then
update_env VITE_TUS_ENDPOINT "${PUBLIC_HOST%/}/tus/files"
else
if [[ -z "$current_tus_endpoint" || "$current_tus_endpoint" == "http://localhost:1080/files" ]]; then
update_env VITE_TUS_ENDPOINT "http://127.0.0.1:${tusd_port:-13400}/files"
fi
fi
generate_kek() {
if command -v openssl >/dev/null 2>&1; then
openssl rand -base64 32 | tr -d '\n'
@ -284,14 +294,6 @@ update_env TUSD_DATA_DIR_HOST "$BASE_DIR/data/tusd"
if ! grep -qE '^IPFS_GATEWAY_BIND=' "$ENV_FILE"; then
update_env IPFS_GATEWAY_BIND "0.0.0.0"
fi
if [[ -n "${PUBLIC_HOST:-}" ]]; then
update_env VITE_TUS_ENDPOINT "${PUBLIC_HOST%/}/tus/files"
else
if ! grep -qE '^VITE_TUS_ENDPOINT=' "$ENV_FILE"; then
update_env VITE_TUS_ENDPOINT "http://localhost:1080/files"
fi
fi
echo "Config written to $ENV_FILE. Starting containers..."
if ! command -v docker >/dev/null 2>&1; then