-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bottle app does not work after mount #520
Comments
Mounting an application to a prefix path says that everything under that path should be redirected to the mounted app. The URL |
Thanks for looking at it. |
I did some testing and here what I found. from bottle import Bottle, request, response, HTTPError
root_app = Bottle()
home_app = Bottle()
param_app = Bottle()
PREFIX_PARAM = 'params'
HOME_OBJ = {
PREFIX_PARAM: 'Service parameters',
}
PARAM_OBJ = {
'p1': 'Testing param',
}
@home_app.get('/')
def home_list(oid=None):
print '*** home list (%s)' % oid
return HOME_OBJ
@param_app.get('/')
@param_app.get('/<oid>')
def param_list(oid=None):
print '*** param list (%s)' % oid
if oid is not None and oid not in PARAM_OBJ:
raise HTTPError(status=404)
return PARAM_OBJ
# IMPORTANT: Setup home_app mount before root_app
home_app.mount('/%s' % PREFIX_PARAM, param_app)
# http GET localhost:8080/app
# http GET localhost:8080/app/params
# http GET localhost:8080/app/params/p1
path_prefix = '/app'
# http GET localhost:8080
# http GET localhost:8080/params
# http GET localhost:8080/params/p1
#path_prefix = '/'
if path_prefix and len(path_prefix) > 0:
p = path_prefix.strip(' /')
if len(p) > 0:
p = '/%s' % p
else:
p = '/'
else:
p = '/'
print 'Path prefix is [%s]' % p
if len(p) == 0 or p == '/':
root_app.merge(home_app)
else:
root_app.mount(p, home_app)
# XXX Does not work
#home_app.mount('/%s' % PREFIX_PARAM, param_app)
root_app.run(host='localhost', port=8080) Now everything works as intended. |
Consider the following code:
I perform the following requests (using httpie https://github.com/jkbr/httpie):
The last request fails to match the rule
@param_app.get('/<oid>')
.Any clue why this is happening? Is this a
mount(...)
bug?Also, if I use
path_prefix = '/'
(in this case,root_app.merge()
is used), and perform the same requests (with the correct URLs) the last call succeeds.The text was updated successfully, but these errors were encountered: