Moved registering application urls out of the run def
and into their own Added 404 handling Split registration of URLs that use rpc.rpc and others into own def. Seems logical to be able to register separately for later use.
This commit is contained in:
parent
4abfcd2462
commit
ce251a965e
@ -27,13 +27,19 @@ class ApiServerSuperWrap(RPC):
|
|||||||
|
|
||||||
self._config = freqtrade.config
|
self._config = freqtrade.config
|
||||||
|
|
||||||
|
# Register application handling
|
||||||
|
self.register_rest_other()
|
||||||
|
self.register_rest_rpc_urls()
|
||||||
|
|
||||||
thread = threading.Thread(target=self.run, daemon=True)
|
thread = threading.Thread(target=self.run, daemon=True)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
def run(self):
|
def register_rest_other(self):
|
||||||
""" Method that runs forever """
|
#Added as a placeholder for app URLs that are not implemented in rpc.rpc
|
||||||
|
app.register_error_handler(404, self.page_not_found)
|
||||||
|
|
||||||
# defines the url rules available on the api server
|
def register_rest_rpc_urls(self):
|
||||||
|
# register the url rules available on the api server
|
||||||
'''
|
'''
|
||||||
First two arguments passed are /URL and 'Label'
|
First two arguments passed are /URL and 'Label'
|
||||||
Label can be used as a shortcut when refactoring
|
Label can be used as a shortcut when refactoring
|
||||||
@ -43,6 +49,9 @@ class ApiServerSuperWrap(RPC):
|
|||||||
app.add_url_rule('/start', 'start', view_func=self.start, methods=['GET'])
|
app.add_url_rule('/start', 'start', view_func=self.start, methods=['GET'])
|
||||||
app.add_url_rule('/daily', 'daily', view_func=self.daily, methods=['GET'])
|
app.add_url_rule('/daily', 'daily', view_func=self.daily, methods=['GET'])
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
""" Method that runs forever """
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Section to handle configuration and running of the Rest server
|
Section to handle configuration and running of the Rest server
|
||||||
also to check and warn if not bound to a loopback, warn on security risk.
|
also to check and warn if not bound to a loopback, warn on security risk.
|
||||||
@ -81,6 +90,12 @@ class ApiServerSuperWrap(RPC):
|
|||||||
each Telegram command should have a like local substitute
|
each Telegram command should have a like local substitute
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def page_not_found(self, error):
|
||||||
|
# return "404 not found", 404
|
||||||
|
return jsonify({'status': 'error',
|
||||||
|
'reason': '''There's no API call for %s''' % request.base_url,
|
||||||
|
'code': 404}), 404
|
||||||
|
|
||||||
def hello(self):
|
def hello(self):
|
||||||
# For simple rest server testing via browser
|
# For simple rest server testing via browser
|
||||||
# cmds = 'Try uri:/daily?timescale=7 /profit /balance /status
|
# cmds = 'Try uri:/daily?timescale=7 /profit /balance /status
|
||||||
|
Loading…
Reference in New Issue
Block a user