Added centralized templating system with static asset serving.
CI / Formatting (push) Successful in 13s
CI / Linting (push) Successful in 14s
CI / Tests (Python 3.12) (push) Failing after 29s
CI / Tests (Python 3.13) (push) Failing after 29s
CI / Tests (Python 3.14) (push) Failing after 26s
CI / Type Checking (push) Failing after 25s
CI / Spelling (push) Successful in 13s
CI / Formatting (push) Successful in 13s
CI / Linting (push) Successful in 14s
CI / Tests (Python 3.12) (push) Failing after 29s
CI / Tests (Python 3.13) (push) Failing after 29s
CI / Tests (Python 3.14) (push) Failing after 26s
CI / Type Checking (push) Failing after 25s
CI / Spelling (push) Successful in 13s
This commit is contained in:
@@ -19,6 +19,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import logging
|
||||
from collections.abc import Awaitable, Callable, Coroutine
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from aiohttp import web
|
||||
@@ -40,6 +41,8 @@ async def _server_header_middleware(
|
||||
) -> web.StreamResponse:
|
||||
response = await handler(request)
|
||||
response.headers["Server"] = f"Owlbot/{__version__}"
|
||||
if request.path.startswith("/owlbot/static/"):
|
||||
response.headers["Cache-Control"] = "max-age=86400"
|
||||
return response
|
||||
|
||||
|
||||
@@ -79,6 +82,11 @@ class HttpServer:
|
||||
self.app = web.Application(middlewares=[_server_header_middleware])
|
||||
self.app.router.add_post(self.config.webhook_path, self._handle_webhook)
|
||||
|
||||
# Static assets served from the owlbot package.
|
||||
static_dir = Path(__file__).resolve().parent / "static"
|
||||
if static_dir.is_dir():
|
||||
self.app.router.add_static("/owlbot/static", static_dir)
|
||||
|
||||
# Catch-all routes for dynamic module route dispatch.
|
||||
# These single aiohttp routes handle all requests under /owlbot/ and
|
||||
# dispatch them to the appropriate handler via RouteDispatcher lookup
|
||||
|
||||
Reference in New Issue
Block a user