-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
27 lines (25 loc) · 944 Bytes
/
server.py
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
import http.server, socketserver
import re
PORT = 8000
indexFile = open("index.html", "rb")
cacheIndex = indexFile.read()
class SimpleHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
match = re.search("\.(js|ico|html|png|css|map)$", self.path) # self é o this em python
res = None
self.send_response(200)
self.send_header("Cache-Control", "public, max-age=2592000")
if match == None:
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(cacheIndex)
return
filename = self.path[1:]
if(self.path.endswith(".css")):
self.send_header("Content-type", "text/css")
f = open(filename, "rb")
self.end_headers()
self.wfile.write(f.read())
Handler = SimpleHandler
httpd = socketserver.TCPServer(("", PORT), Handler)
httpd.serve_forever()