mirror of
https://github.com/fastapi/full-stack-fastapi-template.git
synced 2026-11-03 12:29:42 +00:00
♻️ Serve frontend from FastAPI (#2393)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
588dfd46e5
commit
e80d92452e
@@ -1,3 +1,21 @@
|
||||
FROM oven/bun:1 AS frontend-build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json bun.lock /app/
|
||||
COPY frontend/package.json /app/frontend/
|
||||
|
||||
WORKDIR /app/frontend
|
||||
|
||||
RUN bun install
|
||||
|
||||
COPY ./frontend /app/frontend
|
||||
|
||||
ARG VITE_API_URL=
|
||||
|
||||
RUN bun run build
|
||||
|
||||
|
||||
FROM python:3.14
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
@@ -33,6 +51,8 @@ COPY ./backend/pyproject.toml ./backend/alembic.ini /app/backend/
|
||||
|
||||
COPY ./backend/app /app/backend/app
|
||||
|
||||
COPY --from=frontend-build /app/backend/app/frontend /app/backend/app/frontend
|
||||
|
||||
# Sync the project
|
||||
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
import sentry_sdk
|
||||
from fastapi import FastAPI
|
||||
from fastapi.routing import APIRoute
|
||||
@@ -6,6 +8,8 @@ from starlette.middleware.cors import CORSMiddleware
|
||||
from app.api.main import api_router
|
||||
from app.core.config import settings
|
||||
|
||||
FRONTEND_DIR = Path(__file__).parent / "frontend"
|
||||
|
||||
|
||||
def custom_generate_unique_id(route: APIRoute) -> str:
|
||||
return f"{route.tags[0]}-{route.name}"
|
||||
@@ -31,3 +35,4 @@ if settings.all_cors_origins:
|
||||
)
|
||||
|
||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||
app.frontend("/", directory=FRONTEND_DIR)
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
set -e
|
||||
set -x
|
||||
|
||||
coverage run -m pytest tests/
|
||||
FASTAPI_ENV=development coverage run -m pytest tests/
|
||||
coverage report
|
||||
coverage html --title "${@-coverage}"
|
||||
|
||||
Reference in New Issue
Block a user