Permalink
Browse files

Updated the little serving app to send out redirects for the old site.

  • Loading branch information...
1 parent fd9362a commit 9be22d37354d947bf0af1e851aa4af9f40d1e8d1 @jacobian jacobian committed Sep 25, 2012
Showing with 42 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 Procfile
  3. +35 −2 app.py
  4. +5 −0 requirements.txt
View
1 .gitignore
@@ -0,0 +1 @@
+*.pyc
View
2 Procfile
@@ -1 +1 @@
-web: gunicorn -w4 -b0.0.0.0:$PORT app:app
+web: gunicorn -kgevent -w4 -b0.0.0.0:$PORT app:app
View
37 app.py
@@ -1,4 +1,37 @@
-import os
+"""
+The simplest possible app that can serve these Sphinx docs and issue
+redirects for the previous URLs.
+"""
+
import static
+import selector
+from unipath import FSPath as Path
+
+app = selector.Selector()
+
+def redirect(to):
+ """
+ Create a 301 redirect WSGI app.
+
+ `to` may contain str.format-style formatting which'll be formatted against
+ the routing arguments (wsgiorg.routing_args).
+ """
+ def _redirect(environ, start_response):
+ args, kwargs = environ['wsgiorg.routing_args']
+ start_response('301 MOVED PERMANENTLY',
+ [('Location', to.format(*args, **kwargs))])
+ return []
+ return _redirect
+
+# Redirects for old doc URLs, since Cool URIs Don't Change.
+app.add('/', GET=redirect('/en/2.0/index.html'))
+app.add('/license/', GET=redirect('/en/2.0/license.html'))
+app.add('/about/', GET=redirect('/en/2.0/frontmatter.html'))
+app.add('/en/1.0/', GET=redirect('/en/2.0/index.html'))
+app.add('/en/1.0/{doc:chunk}/', GET=redirect('/en/2.0/{doc}.html'))
+app.add('/en/2.0/{doc:chunk}/', GET=redirect('/en/2.0/{doc}.html'))
-app = static.Cling(os.path.join(os.path.dirname(__file__), '_build/html'))
+# Serve docs at "/en/2.0" still, to leave room for the future.
+# One of these days I'll actually do this, not just talk about it!
+docs = static.Cling(Path(__file__).parent.child('_build', 'html'))
+app.add("/en/2.0|", GET=docs)
View
5 requirements.txt
@@ -1,6 +1,11 @@
docutils==0.9.1
+gevent==0.13.8
+greenlet==0.4.0
gunicorn==0.14.6
Jinja2==2.6
Pygments==1.5
+resolver==0.2.1
+selector==0.9.4
Sphinx==1.1.3
static==0.4
+Unipath==0.2.1

0 comments on commit 9be22d3

Please sign in to comment.