|
12 | 12 | #app.debug = True # Uncomment this if you wish to debug
|
13 | 13 |
|
14 | 14 | port = 8765
|
15 |
| -info = json.load( |
16 |
| - open(os.path.join(os.environ['HOME'], ".smc", "info.json"), 'r')) |
| 15 | +info_path = os.path.join(os.environ['HOME'], ".smc", "info.json") |
| 16 | +info = json.load(open(info_path, 'r')) |
17 | 17 | base_url = "/%s/port/%s" % (info['project_id'], port)
|
18 | 18 |
|
19 | 19 | html_template = """
|
@@ -43,25 +43,48 @@ def info():
|
43 | 43 | <ul>
|
44 | 44 | <li><a href="%(route)s/">%(route)s/ - list of routes</a></li>
|
45 | 45 | <li><a href="%(route)s/get">%(route)s/get - simple get request</a></li>
|
46 |
| - </ul>""" % {'route': base_url} |
| 46 | + <li><a href="%(route)s/header">%(route)s/header - header information</a></li> |
| 47 | + </ul>""" % { |
| 48 | + 'route': base_url |
| 49 | + } |
47 | 50 | return html_template % {'title': 'Info', 'content': content}
|
48 | 51 |
|
49 | 52 |
|
50 | 53 | @app.route(base_url + '/get', methods=['GET'])
|
51 | 54 | def get_something():
|
52 | 55 | content = """<p>Try something like <a href="%(base_url)s/get?something=foo">%(base_url)s/get?something=foo</a></p>""" % {
|
53 |
| - 'base_url': base_url} |
| 56 | + 'base_url': base_url |
| 57 | + } |
54 | 58 | if request.method == 'GET':
|
55 | 59 | something = request.args.get("something", "")
|
56 | 60 | if len(something) > 0:
|
57 | 61 | content = "Got " + something
|
58 | 62 | return html_template % {'title': 'Info', 'content': content}
|
59 | 63 |
|
| 64 | + |
| 65 | +@app.route(base_url + '/header', methods=['GET']) |
| 66 | +def get_header(): |
| 67 | + |
| 68 | + header = '' |
| 69 | + |
| 70 | + for k, v in request.headers.iteritems(): |
| 71 | + header += '{} = {}\n'.format(k, v) |
| 72 | + |
| 73 | + content = ''' |
| 74 | + <div>The header information I got about you ...</div> |
| 75 | + <pre> |
| 76 | + {header} |
| 77 | + </pre> |
| 78 | + '''.format(header=header) |
| 79 | + |
| 80 | + return content |
| 81 | + |
| 82 | + |
60 | 83 | if __name__ == "__main__":
|
61 | 84 | try:
|
62 | 85 | info = json.load(
|
63 | 86 | open(os.path.join(os.environ['HOME'], ".smc", "info.json"), 'r'))
|
64 |
| - print("Try to open https://cloud.sagemath.com" + base_url + '/') |
| 87 | + print("Try to open https://cocalc.com" + base_url + '/') |
65 | 88 | app.run(host='0.0.0.0', port=port)
|
66 | 89 | import sys
|
67 | 90 | sys.exit(0)
|
|
0 commit comments