commit 438cbe0af267dee584a0cb9c0ed3a3f6e86a0f6d Author: Eggert Jung Date: Sun Mar 14 13:26:53 2021 +0100 http server allowing cors diff --git a/pearcopy.py b/pearcopy.py new file mode 100644 index 0000000..c51101c --- /dev/null +++ b/pearcopy.py @@ -0,0 +1,25 @@ +from http.server import HTTPServer, BaseHTTPRequestHandler +import json + + +class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): + def do_POST(self): + content_length = int(self.headers['Content-Length']) + body = self.rfile.read(content_length) + self.send_response(204) + self.send_header('Access-Control-Allow-Origin', '*') + self.end_headers() + #print(body) + for item in body.decode().split(','): + print(item) + + def do_OPTIONS(self): + print(self.headers) + self.send_response(204) + self.send_header('Access-Control-Allow-Origin', '*') + self.send_header('Access-Control-Allow-Method', 'POST, GET, OPTIONS') + self.send_header('Access-Control-Allow-Headers', 'content-type') + self.end_headers() + +httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler) +httpd.serve_forever()