-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy
executable file
·35 lines (27 loc) · 988 Bytes
/
proxy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
import socketserver
import http.server
import urllib.request
# Adapted from the python2 snippet here:
#
# https://levelup.gitconnected.com/how-to-build-a-super-simple-http-proxy-in-python-in-just-17-lines-of-code-a1a09192be00
PORT = 3000
class MyProxy(http.server.SimpleHTTPRequestHandler):
def target_path(self):
# TODO: This is a hack, because it has to be kept synced with whatever static files we use.
if self.path == '/main.js':
return self.path
if self.path == '/style.css':
return self.path
if self.path == '/Lekton-Regular.ttf':
return self.path
else:
return '/'
def do_GET(self):
url='http://127.0.0.1:8000' + self.target_path()
self.send_response(200)
self.end_headers()
self.copyfile(urllib.request.urlopen(url), self.wfile)
httpd = socketserver.ForkingTCPServer(('', PORT), MyProxy)
print ("Now serving at " + str(PORT))
httpd.serve_forever()