Flask App Route + Hops


I am having some issue getting the routes to work for a Flask app, while using Hops. Here is the sample code:

from flask import Flask, request, render_template
import ghhops_server as hs

#Register hops as middleware
app = Flask(__name__)
app.debug = True
hops: hs.HopsFlask = hs.Hops(app)

def help():
    return "Welcome to Grasshopper Hops for CPython!"

if __name__ == "__main__":

When I run this and visit http://localhost:5000/help, it returns with an Error 404, Unknown URI.

If I comment out the line hops: hs.HopsFlask = hs.Hops(app) it works as expected:


When I try to run a different app (app2), that doesn’t initialize the Hops Component, it can also work fine, but I can’t seem to get two different Flask apps to run concurrently via threading or multiprocessing.

Do you know how I can get the routes to work properly, or alternatively, have any suggestions for running multiple Flask apps at the same time from the same script?

Much appreciated!

Update: I made a minor change to hopsflask.py so that it passes the original request through to the controller:

Would need to build out some better handling, but changing lines 32-39 seems to work for me for now:

        if method == "GET":
            res, results = self.query(uri=comp_uri)
            if res:
                response = self._prep_response()
                response.data = results
                return response(environ, start_response)
                return self.wsgi_app(environ, start_response)

Will update when I come up with something better.


@eirannejad is this something we need to change in ghhops-server? I think it is the same as