0

I have a flask app that I test in my dev environment with werkzeug but deploy with Apache and mod_wsgi. In my Apache config I have this classic setting:

WSGIScriptAlias /foo /var/www/html/foo.wsgi

That's great and now my API's URL is like www.blah.com/foo/API/0.1. However, this makes my dev environment's URL www.whatever.com/API/0.1 which is weird, lol.

How can I define an "alias" similar to the one I've defined with Apache so that my URLs served by werkzeug take the form of www.whatever.com/foo/API/0.1?

Thanks!

dmn
  • 965
  • 3
  • 13
  • 24

1 Answers1

0

Finally found the answer but it was not easy to find. So I'm adding this answer here in case anyone's trying the same Google queries I was lol. This is largely based on this answer.

from flask import Blueprint

bp = Blueprint("bar", __name__)

Now I can conditionally register the blueprint with or without a url_prefix. So if my dev mode flag is set:

app.register_blueprint(bp, url_prefix='/foo')

Otherwise, in production:

app.register_blueprint(bp)

Then everywhere I have @app.route() replace it with @bp.route() :)

dmn
  • 965
  • 3
  • 13
  • 24