Skip to content

Instantly share code, notes, and snippets.

@hit9
Forked from lepture/subpath_wsgi.py
Created August 5, 2014 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hit9/6f6dd34c24bef3008ca2 to your computer and use it in GitHub Desktop.
Save hit9/6f6dd34c24bef3008ca2 to your computer and use it in GitHub Desktop.
# coding: utf-8
from flask import Flask
from werkzeug.wsgi import pop_path_info, peek_path_info
from werkzeug.serving import run_simple
app = Flask(__name__)
class PathDispatcher(object):
def __init__(self, default_app, prefix):
self.default_app = default_app
self.prefix = prefix
def __call__(self, environ, start_response):
app = self.default_app
prefix = peek_path_info(environ)
if prefix == self.prefix:
pop_path_info(environ)
return app(environ, start_response)
start_response('404 Not Found', [('Content-Type', 'text/plain')])
return ['Not Found']
@app.route('/')
def hello():
return 'hello'
wsgi = PathDispatcher(app, 'foo')
run_simple('localhost', 5000, wsgi, use_reloader=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment