-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.py
34 lines (30 loc) · 869 Bytes
/
serve.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
28
29
30
31
32
33
34
import http.server
import socketserver
PORT = 8083
class HttpRequestHandler(http.server.SimpleHTTPRequestHandler):
extensions_map = {
'': 'application/json',
'.html': 'text/html',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.svg': 'image/svg+xml',
'.css': 'text/css',
'.js':'application/x-javascript',
'.json': 'application/json',
'.xml': 'application/xml',
'.mjs': 'application/javascript',
}
httpd = socketserver.TCPServer(("localhost", PORT), HttpRequestHandler)
try:
print(f"serving at http://localhost:{PORT}")
httpd.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down server')
httpd.socket.close()
httpd.shutdown()
httpd.server_close()
pass
finally:
httpd.socket.close()
httpd.shutdown()
httpd.server_close()