mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Compare commits
1 commit
main
...
link-rel-a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0a84691c2 |
3 changed files with 19 additions and 2 deletions
|
|
@ -1094,3 +1094,4 @@ async def derive_named_parameters(db, sql):
|
||||||
def add_cors_headers(headers):
|
def add_cors_headers(headers):
|
||||||
headers["Access-Control-Allow-Origin"] = "*"
|
headers["Access-Control-Allow-Origin"] = "*"
|
||||||
headers["Access-Control-Allow-Headers"] = "Authorization"
|
headers["Access-Control-Allow-Headers"] = "Authorization"
|
||||||
|
headers["Access-Control-Expose-Headers"] = "Link"
|
||||||
|
|
|
||||||
|
|
@ -137,10 +137,18 @@ class BaseView:
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
# Hacky cheat to add extra headers
|
||||||
|
headers = {}
|
||||||
|
if "_extra_headers" in context:
|
||||||
|
headers.update(context["_extra_headers"])
|
||||||
return Response.html(
|
return Response.html(
|
||||||
await self.ds.render_template(
|
await self.ds.render_template(
|
||||||
template, template_context, request=request, view_name=self.name
|
template,
|
||||||
)
|
template_context,
|
||||||
|
request=request,
|
||||||
|
view_name=self.name,
|
||||||
|
),
|
||||||
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from datasette.utils import (
|
||||||
is_url,
|
is_url,
|
||||||
path_from_row_pks,
|
path_from_row_pks,
|
||||||
path_with_added_args,
|
path_with_added_args,
|
||||||
|
path_with_format,
|
||||||
path_with_removed_args,
|
path_with_removed_args,
|
||||||
path_with_replaced_args,
|
path_with_replaced_args,
|
||||||
to_css_class,
|
to_css_class,
|
||||||
|
|
@ -958,6 +959,13 @@ class TableView(RowTableShared):
|
||||||
"metadata": metadata,
|
"metadata": metadata,
|
||||||
"view_definition": await db.get_view_definition(table),
|
"view_definition": await db.get_view_definition(table),
|
||||||
"table_definition": await db.get_table_definition(table),
|
"table_definition": await db.get_table_definition(table),
|
||||||
|
"_extra_headers": {
|
||||||
|
"Link": '{}; rel="alternate"; type="application/json+datasette"'.format(
|
||||||
|
self.ds.absolute_url(
|
||||||
|
request, path_with_format(request=request, format="json")
|
||||||
|
),
|
||||||
|
)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue