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

URL_PREFIX is ignored #124

Open
phaoost opened this issue May 25, 2020 · 3 comments
Open

URL_PREFIX is ignored #124

phaoost opened this issue May 25, 2020 · 3 comments

Comments

@phaoost
Copy link

phaoost commented May 25, 2020

~# grep -ri URL_PREFIX /usr/local/lib/python3.7/dist-packages/snappass
~# grep navbar-brand /usr/local/lib/python3.7/dist-packages/snappass/templates/base.html
          <a class="navbar-brand" href="/">Share Secret</a> 

href pointing to / regardless of URL_PREFIX setting

@jparise
Copy link
Collaborator

jparise commented May 26, 2020

It was introduced in #106:

snappass/snappass/main.py

Lines 169 to 170 in 8a3a7f7

if URL_PREFIX:
base_url = base_url + URL_PREFIX.strip("/") + "/"

... and it looks like it hasn't made it into an officially-tagged release yet.

@ucola
Copy link

ucola commented Jan 26, 2021

The URL_PREFIX is only used on the link for the URL. It is never used or implemented to used as subfolder.
If you want to do this, you need to set it on every (in my case /snappass is my subfolder)
@app.route('/snappass/', methods=['GET'])

dont forget to change the app, because the static also need to use the subfolder
app = Flask(name, '/snappass/static/')

@ucola
Copy link

ucola commented Sep 1, 2023

much better is to use the code bellow

`class PrefixMiddleware(object):

def __init__(self, app, prefix=''):
    self.app = app
    self.prefix = prefix

def __call__(self, environ, start_response):

    if environ['PATH_INFO'].startswith(self.prefix):
        environ['PATH_INFO'] = environ['PATH_INFO'][len(self.prefix):]
        environ['SCRIPT_NAME'] = self.prefix
        return self.app(environ, start_response)
    else:
        start_response('404', [('Content-Type', 'text/plain')])
        return ["This url does not belong to the app.".encode()]`

then you only need to add the PrefixMiddleware to the Flask app.

app = Flask(__name__) app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/snappass')

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