Skip to content

Commit

Permalink
serve localhost 8000
Browse files Browse the repository at this point in the history
  • Loading branch information
John Owens committed Oct 9, 2024
1 parent 4643c55 commit f3b10d0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions simple_cors_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
# encoding: utf-8
"""Use instead of `python3 -m http.server` when you need CORS"""

from http.server import HTTPServer, SimpleHTTPRequestHandler


class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
return super(CORSRequestHandler, self).end_headers()


httpd = HTTPServer(('localhost', 8000), CORSRequestHandler)
httpd.serve_forever()

0 comments on commit f3b10d0

Please sign in to comment.