Continuing the previous discussion (
Using a Leo Outline On Another Computer?), we don't even have to change leoserver. Instead, we can import it and monkey patch it. Basically, import leo.core.leoserver, and then add the following:
SetEncoder = leoserver.SetEncoder
InternalServerError = leoserver.InternalServerError
ServerError = leoserver.ServerError
TerminateServer = leoserver.TerminateServer
ServerExternalFilesController = leoserver.ServerExternalFilesController
LeoServer = leoserver.LeoServer
main = leoserver.main
leoserver.wsHost = "10.0.0.58" # If we want to change the default
def send_outline(self, param):
filename = param.get('path', '')
result = ''
if filename and os.path.exists(filename):
with open(filename, encoding = 'utf-8') as f:
result = f.read()
data = {"outline": result}
return self._make_response(data)
LeoServer.send_outline = send_outline
Of course, we could add other new methods the same way. This approach works with my little test client.