Skip to content

Think about CORS #17

@simonw

Description

@simonw

Experimental patch - is this the right approach?

diff --git a/datasette_insert/__init__.py b/datasette_insert/__init__.py
index db10210..159f9d2 100644
--- a/datasette_insert/__init__.py
+++ b/datasette_insert/__init__.py
@@ -14,6 +14,16 @@ async def insert_update(request, datasette):
     table = request.url_vars["table"]
     db = datasette.get_database(database)
 
+    # Handle CORS
+    if request.method == "OPTIONS":
+        r = Response.text("ok")
+        if datasette.cors:
+            r.headers["Access-Control-Allow-Origin"] = "*"
+            r.headers["Access-Control-Allow-Headers"] = "content-type,authorization"
+            r.headers["Access-Control-Allow-Methods"] = "POST"
+        print(r.headers)
+        return r
+
     # Check permissions
     allow_insert_update = False
     allow_create_table = False

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions