def run(port=5000, mongo_host='localhost', mongo_port=27017, pagination_limit=1000000):
client = j.clients.osis.getByInstance('main')
apps = dict()
for namespace in client.listNamespaces():
spec=client.getOsisSpecModel(namespace)
dbname = namespace if namespace != 'system' else 'js_system'
my_settings = {
'MONGO_HOST': mongo_host,
'MONGO_PORT': mongo_port ,
'MONGO_DBNAME': dbname,
'DOMAIN': generateDomain(spec),
'RESOURCE_METHODS': ['GET', 'POST'],
'ITEM_METHODS': ['GET', 'PATCH', 'PUT', 'DELETE'],
'X_DOMAINS': '*',
'MONGO_QUERY_BLACKLIST': [],
'X_HEADERS': ["X-HTTP-Method-Override", 'If-Match'],
'PAGINATION_LIMIT': pagination_limit
}
# init application
app = Eve(__name__, settings=my_settings)
Bootstrap(app)
@app.route('/ui')
def ui():
return render_template('ui.html')
# Unfortunately, eve_docs doesn't support CORS (too bad!), so we had to reimplement it ourselves
@app.route('/docs/spec.json')
def specs():
return send_response(None, [get_cfg()])
apps['/%s' % namespace] = app
print "visit:\nhttp://localhost:%s/docs/" % port
if apps:
firstapp = apps.values()[0]
application = DispatcherMiddleware(firstapp, apps)
# let's roll
run_simple('0.0.0.0', port, application, use_reloader=False)
评论列表
文章目录