Skip to content
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

uwsgi routes / to the first mounted app, even though path doesn't match route #1935

Open
reece opened this issue Nov 29, 2018 · 2 comments
Open

Comments

@reece
Copy link

reece commented Nov 29, 2018

uwsgi 2.0.17.1, Python 3.6

Problem

uwsgi routes / to the first mounted app, even though / does not match the route mount path.

Steps to reproduce:

snafu$ python3.6 -mvenv venv/3.6
snafu$ . venv/3.6/bin/activate
(3.6) snafu$ pip install -U pip setuptools
(3.6) snafu$ pip install uwsgi flask

(3.6) snafu$ head bug1.py uwsgi.ini
==> bug1.py <==
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "You may call me " + __name__ + "\n"

==> uwsgi.ini <==
[uwsgi]
mount = /bug1=bug1.py
callable = app
http-socket = :9090

Start with uwsgi --ini=uwsgi.ini. In another window:

(3.6) snafu$ for url in http://localhost:9090/{bug1/,bug/,}; do (set -x; curl $url); done
+ curl http://localhost:9090/bug1/
You may call me uwsgi_file_bug1
+ curl http://localhost:9090/bug/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>
+ curl http://localhost:9090/
You may call me uwsgi_file_bug1

Logs in first window:

[pid: 19540|app: 0|req: 1/1] 127.0.0.1 () {24 vars in 242 bytes} [Wed Nov 28 21:21:34 2018] GET /bug1/ => generated 32 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 79 bytes (1 switches on core 0)
[pid: 19540|app: 0|req: 2/2] 127.0.0.1 () {24 vars in 240 bytes} [Wed Nov 28 21:21:34 2018] GET /bug/ => generated 233 bytes in 8 msecs (HTTP/1.1 404) 2 headers in 72 bytes (1 switches on core 0)
[pid: 19540|app: 0|req: 3/3] 127.0.0.1 () {22 vars in 232 bytes} [Wed Nov 28 21:21:34 2018] GET / => generated 32 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 79 bytes (1 switches on core 0)
@eclectronical
Copy link

eclectronical commented Oct 8, 2019

It's a shame you didn't get any response from the maintainers after all this time, but the answer is to use --no-default-app (or no-default-app = 1 in an .ini file). This is documented, but not very well.

Unfortunately this still doesn't work quite right as it returns a 500 instead of a 404 for requests that don't hit any app.

@ApproximateIdentity
Copy link

Thank you for the information @eclectronical

Unfortunately this still doesn't work quite right as it returns a 500 instead of a 404 for requests that don't hit any app.

Does anyone here know if this is the intended behaviour? In other words, would the fact that 500 in this instance be considered a bug by the uwsgi team? In that case a fix would be appropriate.

ApproximateIdentity added a commit to ApproximateIdentity/uwsgi that referenced this issue Sep 10, 2021
Currently an error code of 500 is returned when no app is found for a
route, but this changes it to a 404 which seems more appropriate. See
this issue for more context:

    unbit#1935
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants