Dockerfile
和
vercel.json
配置。
flask run
,并且图像是按预期生成的。 在部署后,访问端点(例如,
/generate_image?name=John
)后,浏览器下载
app.py
# Use an official Python image
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Install system dependencies for Pillow (libjpeg, zlib)
RUN apt-get update && apt-get install -y libjpeg-dev zlib1g-dev
# Copy project files into the container
COPY . /app
# Copy the fonts directory into the Docker container
COPY fonts /app/fonts
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Expose the Flask port
EXPOSE 8000
# Install gunicorn (if not already in requirements.txt)
RUN pip install gunicorn
# Run the Flask app with gunicorn for production
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]
{
"version": 2,
"builds": [
{
"src": "Dockerfile",
"use": "@vercel/docker"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/app.py"
}
],
"functions": {
"app.py": {
"runtime": "python3.9",
"includeFiles": "fonts/*"
}
},
"build": {
"env": {
"LD_LIBRARY_PATH": "/usr/lib"
}
}
}
访问时,它应该生成并显示一个名称的第一个字母作为png格式的图像的图像。 相反,浏览器开始下载/generate_image?name=John
我需要修改我的Vercel配置或Dockerfile以正确处理请求吗? 在
app.py
文件中如何配置路线有什么问题?
您可以在此处查看GitHub上的完整项目:
通货形图像生成器repo
tron使用要求。txt和更改副本
vercel.json
现在更改您的Dockerfile
flask
flask-smorest
python-dotenv
sqlalchemy
flask-sqlalchemy
flask-jwt-extended
passlib
flask-migrate
gunicorn
在当地的Docker run。