mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Move CORS headers into base class, refs #1922
This commit is contained in:
parent
31d6a0bc5e
commit
9a1536b52a
1 changed files with 5 additions and 7 deletions
|
|
@ -78,15 +78,10 @@ class BaseView:
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
response = Response.text("Method not allowed", status=405)
|
response = Response.text("Method not allowed", status=405)
|
||||||
if self.ds.cors:
|
|
||||||
add_cors_headers(response.headers)
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def options(self, request, *args, **kwargs):
|
async def options(self, request, *args, **kwargs):
|
||||||
r = Response.text("ok")
|
return Response.text("ok")
|
||||||
if self.ds.cors:
|
|
||||||
add_cors_headers(r.headers)
|
|
||||||
return r
|
|
||||||
|
|
||||||
async def get(self, request, *args, **kwargs):
|
async def get(self, request, *args, **kwargs):
|
||||||
return await self.method_not_allowed(request)
|
return await self.method_not_allowed(request)
|
||||||
|
|
@ -107,7 +102,10 @@ class BaseView:
|
||||||
if self.ds:
|
if self.ds:
|
||||||
await self.ds.refresh_schemas()
|
await self.ds.refresh_schemas()
|
||||||
handler = getattr(self, request.method.lower(), None)
|
handler = getattr(self, request.method.lower(), None)
|
||||||
return await handler(request)
|
response = await handler(request)
|
||||||
|
if self.ds.cors:
|
||||||
|
add_cors_headers(response.headers)
|
||||||
|
return response
|
||||||
|
|
||||||
async def render(self, templates, request, context=None):
|
async def render(self, templates, request, context=None):
|
||||||
context = context or {}
|
context = context or {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue