diff --git a/app/config.py b/app/config.py index 37b5984..d6b6c82 100644 --- a/app/config.py +++ b/app/config.py @@ -20,6 +20,7 @@ class Settings(BaseSettings): # Set to False if you have users from external organizations entraid_validate_issuer: bool = True environment: Literal["development", "staging", "production"] = "development" + hostname: Optional[str] = None log_level: str = "INFO" public_addin_store: bool = False static_dir: Path = base_dir / "static" diff --git a/app/main.py b/app/main.py index 1b26524..329407f 100644 --- a/app/main.py +++ b/app/main.py @@ -11,6 +11,7 @@ from . import settings from .routers import socketio as socketio_router from .routers.macros.router import router as macros_router +from .routers.manifest import router as manifest_router from .routers.taskpane import router as taskpane_router from .routers.xlwings import router as xlwings_router @@ -42,6 +43,7 @@ app.include_router(xlwings_router) app.include_router(macros_router) app.include_router(taskpane_router) +app.include_router(manifest_router) # Security headers diff --git a/app/routers/manifest.py b/app/routers/manifest.py new file mode 100644 index 0000000..14834a7 --- /dev/null +++ b/app/routers/manifest.py @@ -0,0 +1,41 @@ +import logging +import os + +from fastapi import APIRouter, Request + +from ..config import settings +from ..templates import TemplateResponse + +router = APIRouter() + +logger = logging.getLogger(__name__) + + +@router.get("/manifest") +async def manifest(request: Request): + logger.info(os.environ) + logger.info(os.getenv("RENDER_EXTERNAL_URL")) + if settings.hostname: + # Settings + if settings.hostname.startswith("https://"): + hostname = settings.hostname[8:] + else: + hostname = settings.hostname + base_url = f"https://{hostname}" + elif os.getenv("RENDER_EXTERNAL_URL"): + # Render + base_url = os.getenv("RENDER_EXTERNAL_URL") + logger.info(base_url) + elif os.getenv("WEBSITE_HOSTNAME"): + # Azure Functions + base_url = os.getenv("WEBSITE_HOSTNAME") + else: + # Mostly localhost + base_url = request.base_url + + return TemplateResponse( + request=request, + name="/manifest.xml", + context={"settings": settings, "base_url": str(base_url).rstrip("/")}, + media_type="text/plain", + ) diff --git a/manifest.xml b/app/templates/manifest.xml similarity index 75% rename from manifest.xml rename to app/templates/manifest.xml index 2546bde..2afd393 100644 --- a/manifest.xml +++ b/app/templates/manifest.xml @@ -1,8 +1,10 @@ - + xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" + xsi:type="TaskPaneApp"> 0a856eb1-91ab-4f38-b757-23fbe1f73130 1.0.0 @@ -10,11 +12,11 @@ en-US - - + + - https://127.0.0.1:8000 + {{ base_url }} @@ -22,33 +24,34 @@ - + - + ReadWriteDocument - + - - + - + - + - + @@ -56,7 +59,6 @@ - - @@ -119,19 +119,19 @@ - - - + + + - - - + + + - + @@ -143,14 +143,15 @@ - - + + {% endif %}