forked from Data-Wrangling-and-Visualisation/ClimatePulse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
20 lines (16 loc) · 675 Bytes
/
server.py
File metadata and controls
20 lines (16 loc) · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import http.server
import socketserver
PORT = 8000
class CORSRequestHandler(http.server.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')
super().end_headers()
def guess_type(self, path):
if path.endswith('.js'):
return 'application/javascript'
return super().guess_type(path)
with socketserver.TCPServer(("", PORT), CORSRequestHandler) as httpd:
print(f"Serving at http://localhost:{PORT}")
httpd.serve_forever()