Skip to content

Instantly share code, notes, and snippets.

@amriunix
Created March 29, 2020 15:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amriunix/00c4209ba7ecf384e925fc99d98658c5 to your computer and use it in GitHub Desktop.
Save amriunix/00c4209ba7ecf384e925fc99d98658c5 to your computer and use it in GitHub Desktop.
Python3 HTTP Server to enable CORS (Cross-Origin Resource Sharing)
#!/usr/bin/env python3
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__':
test(CORSRequestHandler, HTTPServer, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
@GitHub30
Copy link

awesome!

@DearFox
Copy link

DearFox commented May 19, 2023

not opening in browser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment