by Anonymous » 11 Feb 2025, 14:04
Ich stelle eine Flask -Anwendung auf Vercel mit Docker bereit. Wenn ich jedoch auf meinen Endpunkt zugreife, um ein Bild zu generieren, wird die Datei app.py heruntergeladen, anstatt das erwartete Bild zurückzugeben.
Ich habe eine Dockerfile und eine Vercel.json Konfiguration erstellt. , und das Bild wird wie erwartet generiert. Das Browser lädt die Datei app.py herunter, anstatt das Bild anzuzeigen. = "Lang-none hübschprint-override">
Code: Select all
# 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"]
< /code>
vercel.json:
{
"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"
}
}
}
< /code>
Beim Besuch /Generate_image? name = John < /code> sollte es ein Bild mit dem ersten Buchstaben des Namens als Bild im PNG -Format generieren und anzeigen. Stattdessen beginnt der Browser mit dem Herunterladen der Datei app.py
, anstatt das Bild wie erwartet zurückzugeben. Stimmt etwas nicht, wie die Routen in der Datei von Vercel.json konfiguriert sind?>
Ich stelle eine Flask -Anwendung auf Vercel mit Docker bereit. Wenn ich jedoch auf meinen Endpunkt zugreife, um ein Bild zu generieren, wird die Datei app.py heruntergeladen, anstatt das erwartete Bild zurückzugeben.
Ich habe eine Dockerfile und eine Vercel.json Konfiguration erstellt. , und das Bild wird wie erwartet generiert. Das Browser lädt die Datei app.py herunter, anstatt das Bild anzuzeigen. = "Lang-none hübschprint-override">[code]# 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"]
< /code>
vercel.json:
{
"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"
}
}
}
< /code>
Beim Besuch /Generate_image? name = John < /code> sollte es ein Bild mit dem ersten Buchstaben des Namens als Bild im PNG -Format generieren und anzeigen. Stattdessen beginnt der Browser mit dem Herunterladen der Datei app.py [/code], anstatt das Bild wie erwartet zurückzugeben. Stimmt etwas nicht, wie die Routen in der Datei von Vercel.json konfiguriert sind?>