Tiny HTTP server that sets CORS header 05/2305/2
authorLott, Christopher (cl778h) <cl778h@att.com>
Thu, 12 Jul 2018 12:47:23 +0000 (08:47 -0400)
committerLott, Christopher (cl778h) <cl778h@att.com>
Thu, 12 Jul 2018 12:57:47 +0000 (08:57 -0400)
Change-Id: Ia3d9f5b13a22a2b6fcc721b1b8b6bc69f2f6a303
Issue-ID: ACUMOS-1346
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
docs/tutorials/demonstration.rst
web_demo/simple-cors-http-server-python3.py [new file with mode: 0644]

index a511be0..21ce3b1 100644 (file)
@@ -62,13 +62,13 @@ if you've created a dumped model locally, it might be a localhost port.
 Local webserver run
 -------------------
 
-If you want to run the test locally, you can use the built-in python
+If you want to run the test locally, you can use a supplied python
 webserver with the line below while working in the ``web_demo``
 directory (assuming you're running python3).
 
 ::
 
-    python -m http.server 5000
+    python simple-cors-http-server-python3.py 5000
 
 Afterwards, just point your browser at
 ``http://localhost:5000/face-privacy.html``.
diff --git a/web_demo/simple-cors-http-server-python3.py b/web_demo/simple-cors-http-server-python3.py
new file mode 100644 (file)
index 0000000..b61e2e7
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+# Trivial HTTP server that sets an anything-goes CORS header
+# Defaults to port 8000; accepts alternate port number as sole argument
+# https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server
+
+from http.server import HTTPServer, SimpleHTTPRequestHandler, test
+import sys
+
+class CORSRequestHandler (SimpleHTTPRequestHandler):
+    def end_headers (self):
+        self.send_header('Access-Control-Allow-Origin', '*')
+        SimpleHTTPRequestHandler.end_headers(self)
+
+if __name__ == '__main__':
+    port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
+    test(CORSRequestHandler, HTTPServer, port=port)