Frontend: src/uploads.js is the one way to store or show a file (uploadFile, ACCEPT, kindOf, isUploadUrl, tagFor, mediaSize). Chat, the box editor, canvas drops and the background editor all use it; views/home3/upload.js and the chat store's own axios call are gone. Backend: POST /api/uploads (was /messages/upload) is a thin wrapper over services.Uploads.Save, which owns validation, naming and storage. The three per-extension maps are now one UploadTypes table, and a refused file is an *UploadError whose message is safe to show. nginx now fetches /uploads/ from Garage first and falls back to the volume on a 404 or any 5xx, so the bucket is the source of truth and deleting a file in garage-webui unpublishes it, while a Garage outage still only affects bucket-only files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
88 lines
4.5 KiB
Plaintext
88 lines
4.5 KiB
Plaintext
# =============================================================================
|
|
# nginx_dev_common.conf.template — SHARED BODY of the dev :80 and :443 server
|
|
# blocks.
|
|
#
|
|
# WHY THIS FILE EXISTS
|
|
# In dev the :80 and :443 server blocks are byte-for-byte identical apart
|
|
# from `listen` and the self-signed `ssl_certificate` pair. They used to be
|
|
# ~190 duplicated lines, so every routing fix had to be made twice and could
|
|
# silently drift. Both blocks now `include` this partial instead.
|
|
#
|
|
# HOW IT IS RENDERED
|
|
# nginx/entrypoint.sh runs the SAME envsubst allow-list over this file as
|
|
# over nginx_dev.conf.template, writing the result to
|
|
# /etc/nginx/nginx_dev_common.conf — which is exactly the path the two
|
|
# `include` directives in the rendered nginx.conf point at. If you add
|
|
# a new substituted variable here, it must also be added to ENVSUBST_VARS in
|
|
# the entrypoint, or it will reach nginx unsubstituted.
|
|
#
|
|
# WHAT BELONGS HERE
|
|
# Only what dev does DIFFERENTLY from production inside a server block: the
|
|
# /uploads/ locations without security headers, and `/` proxied to Vite.
|
|
# Everything else — the `set $upstream_*` vars and every reverse-proxied
|
|
# route — is in nginx_routes.conf.template, shared with production and
|
|
# included at the bottom of this file. ADD NEW PROXIED ROUTES THERE, not
|
|
# here.
|
|
# NOT `listen`, `server_name` or the ssl_certificate lines (those differ
|
|
# between the two blocks), and NOT the enclosing braces — this file must be
|
|
# brace-balanced on its own.
|
|
#
|
|
# This is the DEV file only. Production's single :443 www server block in
|
|
# nginx.conf.template includes nginx_routes.conf directly.
|
|
# =============================================================================
|
|
# PRIVATE attachments (admin-only). Attachments on *private* chat
|
|
# messages are written by the backend to /backend/uploads/private/ and
|
|
# must not be readable by the public, so this subpath is put behind the
|
|
# same admin `auth_request` used for /sb/. nginx picks
|
|
# the LONGEST matching prefix location, so this block wins over the
|
|
# public /uploads/ block below for /uploads/private/* regardless of
|
|
# ordering. Same three hardening headers as the public block, because
|
|
# the bytes are just as attacker-supplied.
|
|
location /uploads/private/ {
|
|
auth_request /internal/auth/admin-validate;
|
|
error_page 401 403 = @auth_denied;
|
|
alias /uploads/private/;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header Content-Disposition "inline" always;
|
|
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
|
|
}
|
|
|
|
# The /uploads/ blocks (and @uploads_disk) are the production ones MINUS
|
|
# `include security_headers.conf`: that file carries HSTS, which must
|
|
# never be sent from localhost. That one line is why they are not in
|
|
# the shared route table (see WHAT DOES NOT in
|
|
# nginx_routes.conf.template). Keep the rest in step with
|
|
# nginx.conf.template.
|
|
location /uploads/ {
|
|
rewrite ^/uploads/(.*)$ /$1 break;
|
|
proxy_pass $upstream_garage_web;
|
|
proxy_set_header Host uploads.web.garage;
|
|
proxy_connect_timeout 2s;
|
|
proxy_intercept_errors on;
|
|
error_page 404 500 502 503 504 = @uploads_disk;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header Content-Disposition "inline" always;
|
|
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
|
|
}
|
|
|
|
location @uploads_disk {
|
|
root /uploads;
|
|
try_files $uri =404;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header Content-Disposition "inline" always;
|
|
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
|
|
}
|
|
|
|
# The Vite dev server; Upgrade/Connection carry its HMR websocket.
|
|
location / {
|
|
proxy_pass http://vue:5173;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
}
|
|
|
|
# Every other route, shared with production. This file has no regex
|
|
# locations of its own, so where the include sits is cosmetic.
|
|
include /etc/nginx/nginx_routes.conf;
|