Created
May 14, 2019 12:50
-
-
Save CloudNiner/2f1734f13af34337c4aa284d1b177d8e to your computer and use it in GitHub Desktop.
Serve Vector Tiles locally via dev Python HTTP Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Run with `python3 serve_vt.py <port>` within the directory you want to serve | |
# Credit https://github.com/moradology | |
try: | |
# Python 3 | |
from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig | |
import sys | |
def test (*args): | |
test_orig(*args, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000) | |
except ImportError: # Python 2 | |
from BaseHTTPServer import HTTPServer, test | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
class CORSRequestHandler (SimpleHTTPRequestHandler): | |
def end_headers (self): | |
self.send_header('Content-Encoding', 'gzip') | |
self.send_header('Access-Control-Allow-Origin', '*') | |
SimpleHTTPRequestHandler.end_headers(self) | |
if __name__ == '__main__': | |
test(CORSRequestHandler, HTTPServer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment