Skip to content

Instantly share code, notes, and snippets.

@CloudNiner
Created May 14, 2019 12:50
Show Gist options
  • Save CloudNiner/2f1734f13af34337c4aa284d1b177d8e to your computer and use it in GitHub Desktop.
Save CloudNiner/2f1734f13af34337c4aa284d1b177d8e to your computer and use it in GitHub Desktop.
Serve Vector Tiles locally via dev Python HTTP Server
#!/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