-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.py
38 lines (33 loc) · 1017 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
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
#test on python 3.4 ,python of lower version has different module organization.
#https://gist.github.com/HaiyangXu/ec88cbdce3cdbac7b8d5
import http.server
from http.server import HTTPServer, BaseHTTPRequestHandler
import socketserver
import socket
import sys
PORT = 8080
if len(sys.argv) > 1:
PORT = int(sys.argv[1])
Handler = http.server.SimpleHTTPRequestHandler
Handler.extensions_map={
'.manifest': 'text/cache-manifest',
'.html': 'text/html',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.webp': 'image/webp',
'.svg': 'image/svg+xml',
'.css': 'text/css',
'.js': 'application/javascript',
'.json': 'application/json',
'.mjs': 'application/javascript',
'': 'application/octet-stream', # Default
}
if(len(sys.argv) > 2 and sys.argv[2] == "6"):
class HTTP6Server(HTTPServer):
address_family = socket.AF_INET6
httpd = HTTP6Server(("::", PORT), Handler)
else:
httpd = HTTPServer(("", PORT), Handler)
print("serving at port", PORT)
httpd.serve_forever()