Created
November 23, 2017 06:01
-
-
Save williamstein/c69001187923c2a62f1b42126a4a77e8 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
###################################################################### | |
# Copyright (c) 2013, William Stein, Ondrej Certik, All rights reserved. | |
# 2-clause BSD. | |
###################################################################### | |
import json, os, random, BaseHTTPServer | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
info = json.loads(open('/home/user/.smc/info.json').read()) | |
project_id = info['project_id'] | |
ip = info['location']['host'] | |
port = 10000 | |
base = "%s/%s/port/%s/"%(info['base_url'], project_id, port) | |
print "*"*80 + '\n' | |
print " The HTTP server is running at \n" | |
print " https://cocalc.com%s\n"%base | |
print " All collaborators on this project may access the server at the" | |
print " above SSL-encrypted URL, but nobody else can access it." | |
print '\n\n' + "*"*80 + '\n\n' | |
class MyHandler(SimpleHTTPRequestHandler): | |
def do_GET(self): | |
if self.path.startswith(base): | |
self.path = self.path[len(base)-1:] | |
print "Note: path rewritten to:", self.path | |
return SimpleHTTPRequestHandler.do_GET(self) | |
MyHandler.protocol_version = "HTTP/1.0" | |
httpd = BaseHTTPServer.HTTPServer((ip, port), MyHandler) | |
sa = httpd.socket.getsockname() | |
print "Serving HTTP on", sa[0], "port", sa[1], "base", base | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment