Tiny HTTP server that sets CORS header
[face-privacy-filter.git] / web_demo / simple-cors-http-server-python3.py
1 #!/usr/bin/env python3
2 # Trivial HTTP server that sets an anything-goes CORS header
3 # Defaults to port 8000; accepts alternate port number as sole argument
4 # https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server
5
6 from http.server import HTTPServer, SimpleHTTPRequestHandler, test
7 import sys
8
9 class CORSRequestHandler (SimpleHTTPRequestHandler):
10     def end_headers (self):
11         self.send_header('Access-Control-Allow-Origin', '*')
12         SimpleHTTPRequestHandler.end_headers(self)
13
14 if __name__ == '__main__':
15     port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
16     test(CORSRequestHandler, HTTPServer, port=port)