Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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