Let's say you want to serve 2 domains, example1.com and example2.com, from the same app (i.e., using host matching). You also want your static assets for each domain to be served from those domains, e.g., example1.com/static/
and example2.com/static/
. You can almost achieve this in Flask, but not quite.
This code extends Flask's Blueprint
class to make registering hostnames onto a blueprint painless and ensure static assets appear to be served from the appropriate hostname.
By default, Flask supports host matching at the app-level by passing host_matching=True
and a hostname for static_host
when initializing the app. However, there are drawbacks to the current support, especially when using blueprints:
- To match all routes on a blueprint to a host, you must pass the
host
parameter to every route decorator for that blueprint. - The app's static files will always be served