Skip to content

Instantly share code, notes, and snippets.

@williamstein
Created November 23, 2017 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamstein/c69001187923c2a62f1b42126a4a77e8 to your computer and use it in GitHub Desktop.
Save williamstein/c69001187923c2a62f1b42126a4a77e8 to your computer and use it in GitHub Desktop.
#!/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