can somebody give me a hint on how static content is served? I need to "embed" the TG2-app into an existing wsgi-app below a certain path - and obviously serving e.g. the CSS fails miserably. There was the old way of using tg.url and server.webpath (or such) - any such facility available?
Let me know if we need to expose some more configuration information to the user app, all of this was changed sort-of-recently when we cleaned up middleware.py.
On Wed, Jul 9, 2008 at 10:32 AM, Diez B. Roggisch <de...@web.de> wrote:
> Hi,
> can somebody give me a hint on how static content is served? I need to "embed" > the TG2-app into an existing wsgi-app below a certain path - and obviously > serving e.g. the CSS fails miserably. There was the old way of using tg.url > and server.webpath (or such) - any such facility available?
On Jul 9, 4:32 pm, "Diez B. Roggisch" <de...@web.de> wrote:
> Hi,
> can somebody give me a hint on how static content is served? I need to "embed"
> the TG2-app into an existing wsgi-app below a certain path - and obviously
> serving e.g. the CSS fails miserably. There was the old way of using tg.url
> and server.webpath (or such) - any such facility available?
It looks about the same as tg1, looks in controllers.py for tg.url
def url(tgpath, tgparams=None, **kw):
"""
url() re-implementation from TG1
"""
if not isinstance(tgpath, basestring):
tgpath = "/".join(list(tgpath))
if tgpath.startswith("/"):
app_root =
pylons.request.application_url[len(pylons.request.host_url):]
tgpath = app_root + tgpath
tgpath = pylons.config.get("server.webpath", "") + tgpath
result = tgpath
else:
result = tgpath
....
> Let me know if we need to expose some more configuration information > to the user app, all of this was changed sort-of-recently when we > cleaned up middleware.py.
Ahh! That's interesting - and explains some stuff I've seen while source-level-debugging. The Cascade is interersting for me...
And of course the current implementation is a bit warty::
# Static files (If running in production, and Apache or another web # server is handling this static content, remove the following 3 lines) javascripts_app = StaticJavascripts() static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, javascripts_app, app]) return app
Obviously we want that configurable.
I will open a ticket & try and install TG2 from SVN, so that I can propose a solution for this. I guess the best solution would be to have the above code in <myapplication>/controllers/__init__.py or some such location - or the config/middleware.py, that might even be better.
> > Let me know if we need to expose some more configuration information > > to the user app, all of this was changed sort-of-recently when we > > cleaned up middleware.py.
> On Jul 9, 4:32 pm, "Diez B. Roggisch" <de...@web.de> wrote: > > Hi,
> > can somebody give me a hint on how static content is served? I need to > > "embed" the TG2-app into an existing wsgi-app below a certain path - and > > obviously serving e.g. the CSS fails miserably. There was the old way of > > using tg.url and server.webpath (or such) - any such facility available?
> It looks about the same as tg1, looks in controllers.py for tg.url
> On Wednesday 09 July 2008 20:58:42 aspineux wrote:
> > On Jul 9, 4:32 pm, "Diez B. Roggisch" <de...@web.de> wrote:
> > > Hi,
> > > can somebody give me a hint on how static content is served? I need to
> > > "embed" the TG2-app into an existing wsgi-app below a certain path - and
> > > obviously serving e.g. the CSS fails miserably. There was the old way of
> > > using tg.url and server.webpath (or such) - any such facility available?
> > It looks about the same as tg1, looks in controllers.py for tg.url
> can somebody give me a hint on how static content is served? I need to > "embed" the TG2-app into an existing wsgi-app below a certain path - and > obviously serving e.g. the CSS fails miserably. There was the old way of > using tg.url and server.webpath (or such) - any such facility available?
Ok, I created a patch for the ticket. It includes rewrites of tg.middleware an middleware.py_tmpl (so that the app decides on the static rewriting), and tg.url-enclosing of hopefully all relevant template-urls.
Before I attach that, I have some questions I need to have answered:
- where does the sever.webpath config option actually go? Currently, I've put it as this in my development.ini::
- how is server.webpath supposed to be used? The question arises because of the following considerations:
1) if the TG2-app is one of possibly several below a WSGI-app "mounted" to server.webpath, we need to rewrite the PATH_INFO prior to all requests to remove the server.webpath. I've done that, and it makes additionally adjustments to tg.ext.repoze.who necessary (done them also) because of the generated /login and related urls. These need to be prepended with server.webpath.
2) if the TG2-app is below server.webpath in an Apache-environment, it *might* be possible to use mod_rewrite to strip of the path-prefix for us, thus only the generated urls must
I've done everything for 1). If 2) is an actual scenario we want to work with, it might be necessary to introduce another config-variable called server.strip_webpath or so, that controls the adjustment of PATH_INFO.
I think that we should be relying on SCRIPT_NAME in the environ being set properly, and it looks like I need to patch tg.url to make that work right.
When serving behing apache or another server that does the right thing, the SCRIPT_NAME should automatically be set correctly. When it's not we'll need to use some little middleware that sets it right before we get into the tg2 app.
Inside a TG2 app, we can use request.application_url to get the URL including the host name and SCRIPT_NAME but with no PATH_INFO or query string.
On Thu, Jul 10, 2008 at 9:23 AM, Diez B. Roggisch <de...@web.de> wrote:
>> can somebody give me a hint on how static content is served? I need to >> "embed" the TG2-app into an existing wsgi-app below a certain path - and >> obviously serving e.g. the CSS fails miserably. There was the old way of >> using tg.url and server.webpath (or such) - any such facility available?
> Ok, I created a patch for the ticket. It includes rewrites of tg.middleware an > middleware.py_tmpl (so that the app decides on the static rewriting), and > tg.url-enclosing of hopefully all relevant template-urls.
> Before I attach that, I have some questions I need to have answered:
> - where does the sever.webpath config option actually go? Currently, I've put > it as this in my development.ini::
> - how is server.webpath supposed to be used? The question arises because of > the following considerations:
> 1) if the TG2-app is one of possibly several below a WSGI-app "mounted" to > server.webpath, we need to rewrite the PATH_INFO prior to all requests to > remove the server.webpath. I've done that, and it makes additionally > adjustments to tg.ext.repoze.who necessary (done them also) because of the > generated /login and related urls. These need to be prepended with > server.webpath.
> 2) if the TG2-app is below server.webpath in an Apache-environment, it > *might* be possible to use mod_rewrite to strip of the path-prefix for us, > thus only the generated urls must
> I've done everything for 1). If 2) is an actual scenario we want to work with, > it might be necessary to introduce another config-variable called > server.strip_webpath or so, that controls the adjustment of PATH_INFO.