静态资源

main
mula.liu 2025-12-23 19:10:38 +08:00
parent c8caa0d21a
commit fa59dcc05d
3 changed files with 18 additions and 3 deletions

View File

@ -9,6 +9,7 @@ from typing import List
import os
import zipfile
import io
import mimetypes
from pathlib import Path
from app.core.database import get_db
@ -217,11 +218,16 @@ async def get_asset_file(
if not file_path.exists() or not file_path.is_file():
raise HTTPException(status_code=404, detail="文件不存在")
# 根据文件扩展名确定 MIME 类型
mime_type, _ = mimetypes.guess_type(filename)
if mime_type is None:
mime_type = "application/octet-stream"
# 返回文件(流式响应)
return FileResponse(
path=file_path,
filename=filename,
media_type="application/octet-stream"
media_type=mime_type
)

View File

@ -63,6 +63,10 @@ services:
- REDIS_DB=${REDIS_DB:-8}
- SECRET_KEY=${SECRET_KEY:-your-secret-key-change-me-in-production}
- DEBUG=${DEBUG:-false}
- ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-Admin@123456}
- ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.com}
- ADMIN_NICKNAME=${ADMIN_NICKNAME:-系统管理员}
- TZ=Asia/Shanghai
volumes:
- ${STORAGE_PATH:-./storage}:/data/nex_docus_store

View File

@ -12,6 +12,7 @@ server {
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml+rss;
# API 反向代理(代理到后端服务)
# 必须在静态资源规则之前,确保 API 请求优先匹配
location /api/ {
proxy_pass http://backend:8000/api/;
proxy_set_header Host $host;
@ -28,6 +29,10 @@ server {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 禁用缓存API 请求不应该被缓存)
proxy_buffering off;
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 前端路由支持
@ -36,8 +41,8 @@ server {
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
# 前端静态资源缓存(仅针对前端打包后的静态文件)
location ~* ^/assets/.*\.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}