Skip to content

Commit

Permalink
Handling for root only files like robot.txt for url_prefix.
Browse files Browse the repository at this point in the history
Also added app_blog.yaml which is the example app.yaml if you plan to host
your application on /blog instead of root. Fixed few other issues
with url_preifx.
  • Loading branch information
Jai Sharma authored and Arachnid committed Jan 27, 2010
1 parent 101d256 commit c13ceb9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
24 changes: 24 additions & 0 deletions app_blog.yaml
@@ -0,0 +1,24 @@
application: bloggart-demo
version: live
runtime: python
api_version: 1

handlers:
- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin

- url: /_ah/queue/deferred
script: $PYTHON_LIB/google/appengine/ext/deferred/handler.py
login: admin

- url: /blog/admin/.*
script: admin.py
login: admin

- url: /blog/static/([^/]+)/(.*)
static_files: themes/\1/static/\2
upload: themes/[^/]+/static/.*

- url: /.*
script: static.py
16 changes: 15 additions & 1 deletion static.py
Expand Up @@ -18,6 +18,7 @@

HTTP_DATE_FMT = "%a, %d %b %Y %H:%M:%S GMT"

ROOT_ONLY_FILES = ['/robots.txt','/' + config.google_site_verification]

class StaticContent(db.Model):
"""Container for statically served content.
Expand Down Expand Up @@ -116,6 +117,17 @@ def output_content(self, content, serve=True):
self.response.set_status(304)

def get(self, path):
if not path.startswith(config.url_prefix):
if path not in ROOT_ONLY_FILES:
self.error(404)
self.response.out.write(utils.render_template('404.html'))
return
else:
path = path[len(config.url_prefix):]# Strip off prefix
if path in ROOT_ONLY_FILES:# This lives at root
self.error(404)
self.response.out.write(utils.render_template('404.html'))
return
content = get(path)
if not content:
self.error(404)
Expand All @@ -137,7 +149,9 @@ def get(self, path):
self.output_content(content, serve)


application = webapp.WSGIApplication([(config.url_prefix + '(/.*)', StaticContentHandler)])
application = webapp.WSGIApplication([
('(/.*)', StaticContentHandler),
])


def main():
Expand Down
2 changes: 1 addition & 1 deletion themes/default/base.html
Expand Up @@ -25,7 +25,7 @@ <h1 id="logo-text"><a href="{{config.url_prefix}}/" title="">{{config.blog_name}
<form id="quick-search" action="{{config.url_prefix}}/search" method="get">
<p>
<label for="q">Search:</label>
<input type="hidden" name="cref" value="http://{{config.host}}/cse.xml" />
<input type="hidden" name="cref" value="http://{{config.host}}{{config.url_prefix}}/cse.xml" />
<input type="hidden" name="cof" value="FORID:11" />
<input type="hidden" name="ie" value="UTF-8" />
<input class="tbox" type="text" name="q" size="31" />
Expand Down
2 changes: 1 addition & 1 deletion themes/default/search.html
Expand Up @@ -7,7 +7,7 @@
var googleSearchFormName = "cse-search-box";
var googleSearchFrameWidth = 649;
var googleSearchDomain = "www.google.com";
var googleSearchPath = "{{config.url_prefix}}/cse";
var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
{% endblock %}

0 comments on commit c13ceb9

Please sign in to comment.