Skip to content

Commit

Permalink
better handle URL path when app if proxied
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Jan 19, 2024
1 parent 80a86a9 commit ea9c421
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ cdk.out/
.pgdata/
docs/src/api/*

traefik.toml
routes.toml
9 changes: 8 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tipg/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("/")

Expand Down
1 change: 1 addition & 0 deletions tipg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tipg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ea9c421

Please sign in to comment.