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)):