From ea9c42199d37ba66fa0197cf58d67b92705de5e9 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Fri, 19 Jan 2024 17:57:37 +0100 Subject: [PATCH] better handle URL path when app if proxied --- .gitignore | 2 ++ CHANGES.md | 9 ++++++++- tipg/factory.py | 4 ++++ tipg/main.py | 1 + tipg/settings.py | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c25f922d..635af724 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,5 @@ cdk.out/ .pgdata/ docs/src/api/* +traefik.toml +routes.toml diff --git a/CHANGES.md b/CHANGES.md index 227dbb8e..095e876c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). Note: Minor version `0.X.0` update might break the API, It's recommended to pin `tipg` to minor version: `tipg>=0.1,<0.2` +## [0.6.2] - 2024-01-19 + +- add `root_path` API settings +- fix invalid `url` parsing in HTML responses + ## [0.6.1] - 2024-01-11 - use `spatial_extent` and `datetime_extent` configuration options in `CatalogUpdateMiddleware` and `/refresh` endpoint (author @hrodmn, https://github.com/developmentseed/tipg/pull/164) @@ -276,7 +281,9 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin - Initial release -[unreleased]: https://github.com/developmentseed/tipg/compare/0.6.0...HEAD +[unreleased]: https://github.com/developmentseed/tipg/compare/0.6.2...HEAD +[0.6.2]: https://github.com/developmentseed/tipg/compare/0.6.1...0.6.2 +[0.6.1]: https://github.com/developmentseed/tipg/compare/0.6.0...0.6.1 [0.6.0]: https://github.com/developmentseed/tipg/compare/0.5.7...0.6.0 [0.5.8]: https://github.com/developmentseed/tipg/compare/0.5.7...0.5.8 [0.5.7]: https://github.com/developmentseed/tipg/compare/0.5.6...0.5.7 diff --git a/tipg/factory.py b/tipg/factory.py index 5bc5934f..e244d921 100644 --- a/tipg/factory.py +++ b/tipg/factory.py @@ -3,6 +3,7 @@ import abc import csv import json +import re from dataclasses import dataclass, field from typing import Any, Callable, Dict, Generator, Iterable, List, Literal, Optional from urllib.parse import urlencode @@ -119,6 +120,9 @@ def create_html_response( ) -> _TemplateResponse: """Create Template response.""" urlpath = request.url.path + if root_path := request.app.root_path: + urlpath = re.sub(r"^" + root_path, "", urlpath) + crumbs = [] baseurl = str(request.base_url).rstrip("/") diff --git a/tipg/main.py b/tipg/main.py index ce398e4b..743e926c 100644 --- a/tipg/main.py +++ b/tipg/main.py @@ -68,6 +68,7 @@ async def lifespan(app: FastAPI): openapi_url="/api", docs_url="/api.html", lifespan=lifespan, + root_path=settings.root_path, ) # custom template directory diff --git a/tipg/settings.py b/tipg/settings.py index 154adb15..b050136b 100644 --- a/tipg/settings.py +++ b/tipg/settings.py @@ -24,6 +24,7 @@ class APISettings(BaseSettings): cors_origins: str = "*" cachecontrol: str = "public, max-age=3600" template_directory: Optional[str] = None + root_path: str = "" add_tiles_viewer: bool = True