How to implement exclusive_domain=True when using pattern routes?

36 views
Skip to first unread message

Lisandro

unread,
Apr 3, 2017, 1:06:25 PM4/3/17
to web2py-users
When you use parameter router system, you have the possibility to set a dictionary mapping each domain with an app and then set exclusive_domain=True, this way each app is accessible only through its assigned domain.
But how to do that when using pattern routes?

I'm serving several domains; two web2py apps for each domain.
How do I configure routes to allow access to only those two apps per domain?

For example, lets assume we have two domains: recipes.com and traveler.com
Each domain works with two apps:
  • recipes.com
    • applications/recipes/
    • applications/recipes_panel/
  • traveler.com
    • applications/traveler/
    • applications/traveler_panel/

In order to get this to work, first we need routes.py in the main folder of web2py:

routes_app = [
   
(r'.*?://recipes.com:\w* /$anything', r'recipes'),
   
(r'.*?://traveler.com:\w* /$anything', r'traveler')
]


Then, we need applications/recipes/routes.py:
routes_in = [
 
('/', '/recipes/default/index'),
 
('/robots.txt', '/recipes/static/robots.txt'),
 
('/favicon.png', '/recipes/static/custom/favicon.png'),


 
('/download$anything', '/recipes/default/download$anything'),
 
('/panel/download$anything', '/recipes_panel/default/download$anything'),


 
('/static$anything', '/recipes/static$anything'),
 
('/panel/static$anything', '/recipes_panel/static$anything'),


 
('/panel', '/recipes_panel/default/index'),
 
('/panel$anything', '/recipes_panel$anything'),
]

routes_out
= [(x, y) for (y, x) in routes_in]



And then applications/traveler/routes.py
routes_in = [
 
('/', '/traveler/default/index'),
 
('/robots.txt', '/traveler/static/robots.txt'),
 
('/favicon.png', '/traveler/static/custom/favicon.png'),


 
('/download$anything', '/traveler/default/download$anything'),
 
('/panel/download$anything', '/traveler_panel/default/download$anything'),


 
('/static$anything', '/traveler/static$anything'),
 
('/panel/static$anything', '/traveler_panel/static$anything'),


 
('/panel', '/traveler_panel/default/index'),
 
('/panel$anything', '/traveler_panel$anything'),
]

routes_out
= [(x, y) for (y, x) in routes_in]


However, if go to traveler.com/recipes/default/index I can still access "recipes" app, and I don't want that.
Is it possible to restrict the access using pattern based routes?

Massimo Di Pierro

unread,
Apr 12, 2017, 7:24:24 AM4/12/17
to web2py-users
You have to add a rule for that that redirects the route that you do not want to expose to a custom error page.
Reply all
Reply to author
Forward
0 new messages