WoW :D
2010/10/18 Albert Abril <albert.ab...@gmail.com>: > Wow! Thank you Massimo. > Just now I was having that problem. > > On Mon, Oct 18, 2010 at 9:01 AM, Tom Atkins <minkto...@gmail.com> wrote: >> >> Fantastic - thanks Massimo. That is extremely useful - my regex skills >> are pretty poor but this really helps with getting to grips with routes.py. >> Love the 'tips of the day' - keep 'em coming! >> >> On 18 October 2010 03:07, mdipierro <mdipie...@cs.depaul.edu> wrote: >>> >>> I put the script in trunk under scripts/autoroutes.py >>> to use it >>> >>> cp scripts/autoroutes.py routes.py >>> >>> then edit routes.conf >>> >>> as explained below: >>> >>> On Oct 17, 9:03 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: >>> > Replace your web2py/routes.py with this: >>> > >>> > ------------- begin routes.py----------- >>> > try: config=open('routes.conf','r').read() >>> > except: config='' >>> > def auto_in(apps): >>> > routes=[ >>> > ('/robots.txt','/welcome/static/robots.txt'), >>> > ('/favicon.ico','/welcome/static/favicon.ico'), >>> > ('/admin$a','/admin$a'), >>> > ] >>> > for a,b in [x.strip().split() for x in apps.split('\n') \ >>> > if x.strip() and not x.strip().startswith('#')]: >>> > if not b.startswith('/'): b='/'+b >>> > if b.endswith('/'): b=b[:-1] >>> > app = b.split('/')[1] >>> > routes+=[ >>> > ('.*:https?://(.*\.)?%s:$method /' % a,'%s' % b), >>> > ('.*:https?://(.*\.)?%s:$method /static/$a' % a,'%s/static/ >>> > $a' % app), >>> > ('.*:https?://(.*\.)?%s:$method /appadmin/$a' % a,'%s/ >>> > appadmin/$a' % app), >>> > ('.*:https?://(.*\.)?%s:$method /$a' % a,'%s/$a' % b), >>> > ] >>> > return routes >>> > >>> > def auto_out(apps): >>> > routes=[] >>> > for a,b in [x.strip().split() for x in apps.split('\n') \ >>> > if x.strip() and not x.strip().startswith('#')]: >>> > if not b.startswith('/'): b='/'+b >>> > if b.endswith('/'): b=b[:-1] >>> > app = b.split('/')[1] >>> > routes+=[ >>> > ('%s/static/$a' % app,'static/$a'), >>> > ('%s/appadmin/$a' % app, '/appadmin/$a'), >>> > ('%s/$a' % b, '/$a'), >>> > ] >>> > return routes >>> > >>> > routes_in=auto_in(config) >>> > routes_out=auto_out(config) >>> > ------------------- END --------------- >>> > >>> > what does it do? It writes routes for you based on a simpler routing >>> > configuration file called routes.conf. here is an example: >>> > >>> > ----- BEGIN routes.conf------- >>> > 127.0.0.1 /examples/default >>> > domain1.com /app1/default >>> > domain2.com /app2/default >>> > domain3.com /app3/default >>> > ----- END ---------- >>> > >>> > It maps a domain (the left had side) into an app and it shortens the >>> > URLs for the app, by removing the listed path prefix. That means >>> > >>> > http://domain1.com/indexwill be mapped into >>> > /app1/default/indexhttp://domain2.com/indexwill be mapped into >>> > /app2/default/index >>> > >>> > It is safe in that it preserves admin, appadmin, static files, >>> > favicon.ico and robots.txt. >>> > >>> > >>> > http://domain1.com/favicon.icohttp://domain1.com/robots.txthttp://domain1.com/admin/... >>> > /admin/...http://domain1.com/appadmin/... >>> > /app1/appadmin/...http://domain1.com/static/... /app1/static/... >>> > >>> > and vice-versa. >>> > >>> > It does assume one app per domain. >>> > >>> > I think something like this should be default since lots of people >>> > find routes.py hard to work with. >>> > Comments? Suggestions? >>> > >>> > Massimo > >