This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.py
74 lines (56 loc) · 2.14 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
import flask
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--rpc', action='store_true', default=False)
parser.add_argument('--rest', action='store_true', default=False)
parser.add_argument('--no-websockets', action='store_true', default=False)
parser.add_argument('--cross-origin', action='store_true', default=False)
parser.add_argument('--port', type=int, default=8000)
parser.add_argument('--root', type=str, default='/api')
args = parser.parse_args()
method = 'rpc'
if args.rest:
method = 'rest'
if method == 'rpc':
from agent import rpc as blueprint
elif method == 'rest':
from agent import rest as blueprint
if __name__ == '__main__':
app = flask.Flask(__name__, template_folder='./')
app.config['SECRET_KEY'] = 'secret'
@app.route('/')
def index():
return flask.render_template('test.html')
@app.route('/mocha.js')
def mochajs():
return open('./node_modules/mocha/mocha.js').read()
@app.route('/mocha.css')
def mochacss():
return open('./node_modules/mocha/mocha.css').read()
@app.route('/test.browser.js')
def test():
return open('test.browser.js').read()
@app.route('/conda.js')
def conda():
return open('conda.js').read()
print("Using method", method)
blueprint.conda_js.url_prefix = args.root
if args.cross_origin:
print("Allowing cross origin responses")
@blueprint.conda_js.after_request
def add_cross_origin(response):
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
return response
app.register_blueprint(blueprint.conda_js)
if '--no-progress' in sys.argv:
app.run(port=args.port, debug=True)
else:
print("Using websockets")
import tornado.ioloop
from agent.websocket import wrap
wsgi_app, application = wrap(app, args.root + '_ws', debug=False)
application.listen(args.port)
tornado.ioloop.IOLoop.instance().start()