Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions example/vite-app/bootstrap/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from fastapi_startkit.logging import LogProvider
from fastapi_startkit.vite import ViteProvider

# from config.vite import ViteConfig
from providers.fastapi_provider import FastAPIProvider

app: Application = Application(
base_path=Path(__file__).resolve().parent.parent,
providers=[
LogProvider,
FastAPIProvider,
# ViteProvider auto-binds a Jinja2Templates engine (with the vite()
# globals injected) at the configured templates directory.
(ViteProvider, {"templates_directory": "templates"}),
ViteProvider,
],
)
8 changes: 8 additions & 0 deletions example/vite-app/providers/fastapi_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from pathlib import Path

from fastapi import FastAPI
from starlette.templating import Jinja2Templates

from fastapi_startkit.fastapi import FastAPIProvider as BaseFastAPIProvider

Expand All @@ -11,6 +14,11 @@ def register(self) -> None:
)
self.app.use_fastapi(fastapi)

# Bind Jinja2Templates so ViteProvider can inject vite() globals into it.
templates_dir = Path(self.app.base_path) / "templates"
templates = Jinja2Templates(directory=str(templates_dir))
self.app.bind("templates", templates)

def boot(self) -> None:
super().boot()

Expand Down
11 changes: 6 additions & 5 deletions example/vite-app/routes/web.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from fastapi import APIRouter
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse

from fastapi_startkit.vite import template

web = APIRouter()


@web.get("/", response_class=HTMLResponse)
async def index():
return template("index.html")
async def index(request: Request):
from bootstrap.application import app

templates = app.make("templates")
return templates.TemplateResponse(request, "index.html")


@web.get("/api/health")
Expand Down
9 changes: 0 additions & 9 deletions fastapi_startkit/src/fastapi_startkit/fastapi/context.py

This file was deleted.

20 changes: 0 additions & 20 deletions fastapi_startkit/src/fastapi_startkit/fastapi/middleware.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ def register(self) -> None:
def boot(self):
import os

from fastapi_startkit.fastapi.middleware import RequestContextMiddleware

self.commands([ServeCommand])
self._register_exception_handlers()
self.app.add_middleware(RequestContextMiddleware)

source = os.path.abspath(os.path.join(os.path.dirname(__file__), "../config/fastapi.py"))
self.publishes({source: "config/fastapi.py"})
Expand Down
3 changes: 0 additions & 3 deletions fastapi_startkit/src/fastapi_startkit/vite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from .vite import Vite
from .providers.provider import ViteProvider
from .template import Template, template
from .exceptions import ViteException, ViteManifestNotFoundException

__all__ = [
"Vite",
"ViteProvider",
"Template",
"template",
"ViteException",
"ViteManifestNotFoundException",
]
2 changes: 0 additions & 2 deletions fastapi_startkit/src/fastapi_startkit/vite/config/vite.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ class ViteConfig:
asset_url: str = ""
static_url: str = "/build"
mount_static: bool = True
template: bool = True
templates_directory: str = "resources/templates"
19 changes: 0 additions & 19 deletions fastapi_startkit/src/fastapi_startkit/vite/providers/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,6 @@ def register(self) -> None:

self.app.bind("vite", vite)

self.register_templates(config)

def register_templates(self, config: ViteConfig) -> None:
# Provide a template engine out of the box so fresh apps can render
# views and have the vite() globals injected during boot. An existing
# binding always wins, keeping this backward-compatible.
if not config.template or self.app.has("templates"):
return

try:
from starlette.templating import Jinja2Templates
except ImportError as exc:
raise ImportError(
"Rendering templates requires Jinja2. Install it with: pip install fastapi-startkit[vite]"
) from exc

templates_dir = self.app.base_path / config.templates_directory
self.app.bind("templates", Jinja2Templates(directory=str(templates_dir)))

def boot(self) -> None:
vite: Vite = self.app.make("vite")
config = self.app.make("config").get(self.provider_key)
Expand Down
52 changes: 0 additions & 52 deletions fastapi_startkit/src/fastapi_startkit/vite/template.py

This file was deleted.

85 changes: 0 additions & 85 deletions fastapi_startkit/tests/vite/test_template.py

This file was deleted.

Loading