From 2a0e23bd0b87ebc3022cf8a2996070e22b46552c Mon Sep 17 00:00:00 2001 From: Wizerd Date: Thu, 14 Dec 2023 11:45:00 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E7=9A=84=E8=B7=A8=E5=9F=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- docker-compose.yml | 10 ++++++---- upload.py | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4530c86..9a98798 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ENV PYTHONUNBUFFERED=1 RUN chmod +x /app/start.sh # 安装任何所需的依赖项 -RUN pip install --no-cache-dir flask gunicorn requests Pillow +RUN pip install --no-cache-dir flask gunicorn requests Pillow flask-cors # 在容器启动时运行 Flask 应用 CMD ["/app/start.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 18ed29f..3e3588c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,8 @@ version: '3' services: backend-to-api: - image: wizerd/pandora-to-api:0.0.1 + image: wizerd/pandora-to-api:0.0.4 + restart: always ports: - "50011:33333" environment: @@ -10,13 +11,14 @@ services: - PROXY_API_PREFIX= - UPLOAD_BASE_URL= volumes: - - .:/app + - ./log:/app/log uploader: - image: wizerd/pandora-to-api:0.0.1 + image: wizerd/pandora-to-api:0.0.4 + restart: always entrypoint: ["python3", "/app/upload.py"] volumes: - - .:/app + - ./images:/app/images ports: - "50012:23333" \ No newline at end of file diff --git a/upload.py b/upload.py index 2c3a71c..1dabfad 100644 --- a/upload.py +++ b/upload.py @@ -1,12 +1,15 @@ from flask import Flask, send_from_directory import os +from flask_cors import CORS, cross_origin # 导入 CORS 和 cross_origin app = Flask(__name__) +CORS(app, resources={r"/images/*": {"origins": "*"}}) # 为特定路由配置 CORS # 确保 images 文件夹存在 os.makedirs('images', exist_ok=True) @app.route('/images/') +@cross_origin() # 使用装饰器来允许跨域请求 def get_image(filename): # 检查文件是否存在 if not os.path.isfile(os.path.join('images', filename)):