Last active
August 17, 2017 08:16
-
-
Save allenyang79/ede23ef5f41cc7f97a9e8fd137aba54f to your computer and use it in GitHub Desktop.
custom flask prefix
This file contains hidden or 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, request | |
from werkzeug.serving import run_simple | |
from werkzeug.wsgi import DispatcherMiddleware | |
app = Flask(__name__) | |
app.debug = True | |
@app.route('/') | |
def hello_world(): | |
print 'url', request.url | |
print 'url_root', request.url_root | |
print 'base_url', request.base_url | |
print 'host_url', request.host_url | |
print 'host', request.host | |
print 'query_string', request.query_string | |
print 'scheme', request.scheme | |
print dir(request) | |
return 'Hello World!' | |
def simple(env, resp): | |
resp(b'200 OK', [(b'Content-Type', b'text/plain')]) | |
return [b'Hello WSGI World'] | |
# combine mutli app to uwsgi app. | |
# in this case. we plan to add prefix for my flask app | |
app.wsgi_app = DispatcherMiddleware(simple, {'/abc/123': app.wsgi_app}) | |
if __name__ == '__main__': | |
run_simple('localhost', 5000, app, | |
use_reloader=True, use_debugger=True, use_evalex=True) |
This file contains hidden or 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
url http://localhost:5000/abc/123/ | |
url_root http://localhost:5000/abc/123/ | |
base_url http://localhost:5000/abc/123/ | |
host_url http://localhost:5000/ | |
host localhost:5000 | |
query_string | |
scheme http |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment