Home > Software design >  Flask Blueprint Subdomain Not Working GAE
Flask Blueprint Subdomain Not Working GAE

Time:10-11

I have an application deployed to Google App Engine (GAE) using Flask in a Python 3 Standard Environment, which is working fine. Now, I want to have a subdomain, but I don't want to create a new service for that, as it increases (front-end instance) costs. In my local host I have been able to do it by using Flask Blueprint subdomains, however in my production application, that is not working.

Consider that my application has the following custom DNS configured: example.com, and admin.example.com. This is what I have defined in my application:

app = Flask(__name__)
app.register_blueprint(admin, subdomain='admin')

if __name__ == '__main__':
    app.config['SERVER_NAME'] = 'example.com'
    app.run()

My dispatch.yaml looks like this:

dispatch:
  - url: "*.example.com/*"
    service: default

When I execute locally, I get the expected behavior:

  • Accessing example.com points me to app home page
  • Accessing admin.example.com points me to admin home page

However, in production (GAE) both URLs, point to the app home page.

I've not been able to find much information on this topic. Any hints/suggestions are much appreciated.

Thanks in advance!

CodePudding user response:

I finally found the solution. It turns out that the order matters. This is how I fixed it:

app = Flask(__name__)
app.config['SERVER_NAME'] = 'example.com'

app.register_blueprint(admin, subdomain='admin')

if __name__ == '__main__':
    app.run()
  • Related