so, here's a few tests on the functionality at the current state
(patch applied). Maybe we can sum up a little "recipe" to explain
better
the "interaction" between parameter based and pattern based
rewrite....
These settings for production sites are a real deal, so, here we
are...
The test is a basic app, with an errors/index function expressed as:
def index():
response.status = request.vars.code
return dict(vars=request.vars)
The test is "passed" when:
a) the appname is stripped from the url
b) the error handler doesn't loop forever
c) a request made to http://host.domain/robots.txt returns the
contents of appname/static/robots.txt
d) a request made to http://host.domain/favicon.ico returns the
contents of appname/static/favicon.ico
e) a request made to http://host.domain/sitemap.xml returns the
contents of appname/static/sitemap.xml
TEST 1:
---routes.py---
default_application = 'appname'
routes_onerror = [
('*/*', '/appname/errors/index')
]
results : a) not working (that's expected), b) working, c), d), e) not
working (expected behaviour)
TEST 2:
---routes.py---
default_application = 'appname'
routers = dict(
BASE = dict(
default_application = 'appname',
),
)
routes_onerror = [
('*/*', '/errors/index')
]
results: a) working, b) working, c) working, d) working, e) not
working
---routes.py---
default_application = 'appname'
routes_in = (
('/robots.txt', '/static/robots.txt'),
('/sitemap.xml', '/static/sitemap.xml'),
('/favicon.ico', '/static/favicon.ico'),
)
routes_out = (
('/static/robots.txt', '/robots.txt'),
('/static/sitemap.xml', '/sitemap.xml'),
('/static/favicon.ico', '/favicon.ico'),
)
routers = dict(
BASE = dict(
default_application = 'appname',
),
)
routes_onerror = [
('*/*', '/errors/index')
]
results: a) working, b) working, c) working, d) working, e) not
working
TEST 3:
---routes.py---
default_application = 'appname'
routes_in = (
('/(?P<any>.*)', '/appname/\g<any>'),
('/favicon.ico', '/appname/static/favicon.ico'),
('/sitemap.xml', '/appname/static/sitemap.xml'),
('/robots.txt', '/appname/static/robots.txt')
)
routes_out = (
('/appname/(?P<any>.*)', '/\g<any>'),
('/appname/static/favicon.ico', '/favicon.ico' ),
('/appname/static/robots.txt', '/robots.txt'),
('/appname/static/sitemap.xml', '/sitemap.xml')
)
routes_onerror = [
('*/*', '/errors/index')
]
results: a) working, b) working, c) working, d) working, e) not
working
TEST 4:
default_application = 'appname'
routes_in = (
('/favicon.ico', '/appname/static/favicon.ico'),
('/robots.txt', '/appname/static/robots.txt'),
('/sitemap.xml', '/appname/static/sitemap.xml'),
('/(?P<any>.*)', '/appname/\g<any>')
)
routes_out = (
('/appname/static/favicon.ico', '/favicon.ico' ),
('/appname/static/robots.txt', '/robots.txt'),
('/appname/static/sitemap.xml', '/sitemap.xml'),
('/appname/(?P<any>.*)', '/\g<any>')
)
results: a) working, b) working, c) working, d) working, e) working
So, to sum up, something I think I have learned from the experience:
- pattern-based and parameter-based aren't meant to use together. With
pattern-based system "root files" as robots.txt and favicon.ico are
handled internally but not sitemap.xml (or anything else)
- routes_onerror seems to work independantly of the "rewrite method"
- in pattern-based system the order matters. This is an expected
behaviour but nonetheless worth to remember. As an example, take TEST
3 and TEST 4... sitemap.xml gets "taken" by the ('/(?P<any>.*)', '/
appname/\g<any>') tuple in TEST 3 before the "exact match".
- parameter-based is really helpful to map domains to apps or if you
have multiple apps but only one "preferred", or with language-based
redirections. With parameter-based system you can access other apps by
"normal" non-rewritten urls. With pattern-based if you want to have a
"default" application you have to map any additional application
specifically.