4

I want to setup a catchall subdomain routing system where the subdomain is the user's profile and the domain can be anything so it doesnt have to be set based on the server it is running on.

what I have right now isnt routing I just tried to use a regex to catch everything after the subdomains.

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

so I want to be able to goto a page like username.preset-sub.localhost.com/ and have it be routed to that handler.

BillPull
  • 6,853
  • 15
  • 60
  • 99

1 Answers1

4

I put 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 on the web, will have to add the cname in your cpanel of your domain and admin panel of your application. More information: webapp2 - URI routing - Domain and subdomain routing.

BSMP
  • 4,596
  • 8
  • 33
  • 44
alfredo chuc
  • 129
  • 1
  • 5
  • right but in my situation the first part of the subdomain could be anything and so could the route server so .preset-sub.* so it could work on local dev dev.app.com and web.app.com no matter what they happen to be named. – BillPull Dec 07 '12 at 20:55