4 # Copyright 2016 RIFT.IO Inc
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 from http
.server
import BaseHTTPRequestHandler
, HTTPServer
, SimpleHTTPRequestHandler
33 DEFAULT_ENABLE_HTTPS
= False
34 DEFAULT_KEYFILE_PATH
= None
35 DEFAULT_CERTFILE_PATH
= None
38 enable_https
=DEFAULT_ENABLE_HTTPS
,
39 keyfile_path
=DEFAULT_KEYFILE_PATH
,
40 certfile_path
=DEFAULT_CERTFILE_PATH
):
41 Handler
= SimpleHTTPRequestHandler
42 Handler
.extensions_map
['.svg'] = 'image/svg+xml'
43 httpd
= socketserver
.TCPServer(('', PORT
), Handler
)
47 httpd
.socket
= ssl
.wrap_socket(httpd
.socket
,
49 certfile
=certfile_path
,
52 print("Serving at port: {}. HTTPS Enabled: {}".format(PORT
, enable_https
))
56 def main(argv
=sys
.argv
[1:]):
57 parser
= argparse
.ArgumentParser()
58 parser
.add_argument("-p", "--port",
60 help="Run on the given port")
61 parser
.add_argument("-e", "--enable-https",
64 help="Enable HTTPS. Make sure certfile-path and keyfile-path are also specified")
65 parser
.add_argument("-k", "--keyfile-path",
66 default
=DEFAULT_KEYFILE_PATH
,
67 help="Path to the key file")
68 parser
.add_argument("-c", "--certfile-path",
69 default
=DEFAULT_CERTFILE_PATH
,
70 help="Path to the cert file")
72 args
= parser
.parse_args()
74 # When you want to use the debugger, unremark this before the line you want
75 #import pdb; pdb.set_trace()
78 if not (args
.keyfile_path
and args
.certfile_path
):
82 start_server(args
.enable_https
, args
.keyfile_path
, args
.certfile_path
)
85 if __name__
== '__main__':