Last active
August 29, 2015 14:04
-
-
Save lepture/c1810f51b385d9647295 to your computer and use it in GitHub Desktop.
subpath for wsgi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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