Mercurial > repos > fubar > jbrowse2
diff jb2_webserver.py @ 48:460d5b6c5d98 draft
planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit 3a43e9e0ffce0966101203102e769d1ced28618a-dirty
author | fubar |
---|---|
date | Wed, 06 Mar 2024 10:37:49 +0000 |
parents | 4181e97c70a7 |
children | f350467f9433 |
line wrap: on
line diff
--- a/jb2_webserver.py Wed Mar 06 00:23:02 2024 +0000 +++ b/jb2_webserver.py Wed Mar 06 10:37:49 2024 +0000 @@ -38,11 +38,12 @@ import os import re import socketserver +import ssl import webbrowser from http.server import SimpleHTTPRequestHandler -DEFAULT_PORT = 8081 +DEFAULT_PORT = 8443 def copy_byte_range(infile, outfile, start=None, stop=None, bufsize=16 * 1024): @@ -153,6 +154,17 @@ class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): allow_reuse_address = True + def server_bind(self): + ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ctx.load_cert_chain('cert.pem', 'key.pem') + socketserver.TCPServer.server_bind(self) + self.socket = ctx.wrap_socket( self.socket, server_hostname = "127.0.0.1", server_side=False,) + + + def get_request(self): + (socket, addr) = socketserver.TCPServer.get_request(self) + socket.do_handshake() + return (socket, addr) if __name__ == "__main__": parser = argparse.ArgumentParser( @@ -171,17 +183,17 @@ ) parser.add_argument( "--bind", - default="0.0.0.0", - help="IP address to bind to (default: 0.0.0.0)", + default="127.0.0.1", + help="IP address to bind to (default: 127.0.0.1)", ) args = parser.parse_args() handler = functools.partial(RangeRequestHandler, directory=args.root) - webbrowser.open(f"http://{args.bind}:{args.port}") + webbrowser.open(f"https://{args.bind}:{args.port}") with ThreadedTCPServer((args.bind, args.port), handler) as httpd: print( - f"Serving HTTP on {args.bind} port {args.port} (http://{args.bind}:{args.port}/)" + f"Serving HTTPS on {args.bind} port {args.port} (https://{args.bind}:{args.port}/)" ) httpd.serve_forever()