Search code examples
flaskwerkzeug

werkzeug DispatcherMiddleware with separate ports


I'm playing with combining a couple flask apis that I have into one application that can be a little easier to deploy and set up for devs instead of needing three separate applications running. Currently each api resides on a separate port. I'm trying to use the DispatcherMiddleware to run all three applications but so far it seems like you can only use prefixes like

from frontend import app as frontend
from TestApi import app as test
from DevApi  import app as dev
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware

app = DispatcherMiddleware(frontend, {
    '/test':     test,
    '/dev':      dev
})
run_simple('localhost', 4000, app, use_reloader=True)

now all my services run on 4000 but what id like to have is something like this

from frontend import app as frontend
from TestApi import app as test
from DevApi  import app as dev
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware

app = DispatcherMiddleware(frontend, {
    ':5000':     test,
    ':6000':      dev
})
#frontend runs on 4000, test runs on 5000, dev runs on 6000
run_simple('localhost', 4000, app, use_reloader=True) 

Am I just asking for something that makes no sense or is there a way to accomplish using this or another setup.


Solution

  • I've come to the conclusion that this is a stupid idea that is very fragile and requires a lot of unnecessary complexity. I've instead just opted to write a bash script that starts all the apps as separate wsgi instances on their own port.