forked from Aquaveo/cesium-vr
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server.py: Updated to latest ssl API. Added handler for the src dir
Flag global USE_HTTPS to optionally serve through HTTP. Handler: overrides SimpleHTTPRequestHandler.translate_path to accomodate /src URLs.
- Loading branch information
1 parent
5af8a08
commit dbbee02
Showing
1 changed file
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
from http.server import HTTPServer, SimpleHTTPRequestHandler | ||
import ssl | ||
|
||
#USE_HTTPS = False | ||
USE_HTTPS = True | ||
|
||
if USE_HTTPS: | ||
PORT = 4443 | ||
# https://wiki.debian.org/Self-Signed_Certificate | ||
CERTFILE = './star.pem' # copy from /etc/ssl/certs/ssl-cert-snakeoil.pem for example. | ||
KEYFILE = './star.key' # copy from /etc/ssl/private/ssl-cert-snakeoil.key | ||
else: | ||
PORT=8002 | ||
|
||
class Handler(SimpleHTTPRequestHandler): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, directory='htdocs', **kwargs) | ||
|
||
def translate_path(self, path): | ||
if self.path.startswith('/src/'): | ||
return '.' + path; | ||
return super().translate_path(path); | ||
|
||
print("Configuring Server") | ||
httpd = HTTPServer(('0.0.0.0', 4443), SimpleHTTPRequestHandler) | ||
|
||
httpd.socket = ssl.wrap_socket (httpd.socket, | ||
keyfile="./star.pem", | ||
certfile='./star.pem', server_side=True) | ||
httpd = HTTPServer(('0.0.0.0', PORT), Handler) | ||
if USE_HTTPS: | ||
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) | ||
ssl_context.load_cert_chain(certfile=CERTFILE, keyfile=KEYFILE) | ||
httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True) | ||
|
||
print("Starting Server") | ||
print("Starting server at port " + str(PORT)) | ||
httpd.serve_forever() | ||
print("Done") |