-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserv.py
More file actions
22 lines (18 loc) · 666 Bytes
/
Copy pathserv.py
File metadata and controls
22 lines (18 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from http.server import BaseHTTPRequestHandler
class SimpleServer(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.path = '/index.html'
try:
file_to_open = open(self.path[1:]).read()
self.send_response(200)
except:
file_to_open = "File not found"
self.send_response(404)
self.end_headers()
self.wfile.write(bytes(file_to_open, 'utf-8'))
if __name__ == '__main__':
from http.server import HTTPServer
httpd = HTTPServer(('localhost', 8000), SimpleServer)
print('Starting server, use <Ctrl-C> to stop')
httpd.serve_forever()