Webapp2 routing subdomains for any domain

I want to configure a subdomain routing system in which the subdomain is the user profile, and the domain can be any, so it does not need to be installed on the basis of the server on which it is running.

that I don’t have routing right now, I just tried to use regex to catch everything after subdomains.

routes.DomainRoute('<subdomain>.preset-sub.<.*>', [ webapp2.Route('/<page_url:\w+>', handler = SubHandler), ]), 

so I want to be able to go to a page, for example username.preset-sub.localhost.com/, and pass it to this handler.

+4
source share
1 answer

I will give an example of a project that I am developing, and I had to use to filter the subdomains where to send the URL:

 app = webapp2.WSGIApplication([ routes.DomainRoute('api.domain.com', [ webapp2.Route('/', handler=HomeApi, name='subdomain-home'), webapp2.Route('/user', handler=UserApi, name='subdomain-home'), ]), routes.DomainRoute('web.domain.com', [ webapp2.Route('/', handler=HomeApi, name='subdomain-web-home'), webapp2.Route('/login', handler=Login, name='login-home'), webapp2.Route(r'/products/<product_id:\d+>', ProductHandler), ]), webapp2.Route('/', handler=Home, name='home'), webapp2.Route('/contact', handler=Contact, name='home'), ]) 

if you try online, you will need to add cname to your cpanel of your domain and the admin panel of your application. Additional information: webapp2 - routing URI - routing of the domain and subdomain .

+4
source

All Articles