Skip to content

Instantly share code, notes, and snippets.

@hellctflife
Forked from acdha/simple_cors_server.py
Created February 11, 2021 00:59
Show Gist options
  • Select an option

  • Save hellctflife/910ca1f8b652dc68ec5f2b47e3f545d2 to your computer and use it in GitHub Desktop.

Select an option

Save hellctflife/910ca1f8b652dc68ec5f2b47e3f545d2 to your computer and use it in GitHub Desktop.

Revisions

  1. @acdha acdha revised this gist Sep 29, 2015. No changes.
  2. @acdha acdha created this gist Sep 29, 2015.
    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', 8003), CORSRequestHandler)
    httpd.serve_forever()