datasette.client now applies base_url, closes #1026

This commit is contained in:
Simon Willison 2020-10-31 12:29:42 -07:00
commit 84bc7244c1
5 changed files with 56 additions and 13 deletions

View file

@ -44,6 +44,7 @@ from .url_builder import Urls
from .database import Database, QueryInterrupted
from .utils import (
PrefixedUrlString,
async_call_with_supported_arguments,
await_me_maybe,
call_with_supported_arguments,
@ -1242,9 +1243,12 @@ class NotFoundExplicit(NotFound):
class DatasetteClient:
def __init__(self, ds):
self.ds = ds
self.app = ds.app()
def _fix(self, path):
if not isinstance(path, PrefixedUrlString):
path = self.ds.urls.path(path)
if path.startswith("/"):
path = "http://localhost{}".format(path)
return path

View file

@ -387,9 +387,9 @@ class Response:
)
@classmethod
def json(cls, body, status=200, headers=None):
def json(cls, body, status=200, headers=None, default=None):
return cls(
json.dumps(body),
json.dumps(body, default=default),
status=status,
headers=headers,
content_type="application/json; charset=utf-8",