Incubator-superset: URL Prefix Superset Flask

Created on 18 Oct 2017  路  21Comments  路  Source: apache/incubator-superset

Make sure these boxes are checked before submitting your issue - thank you!

  • [*] I have checked the superset logs for python stacktraces and included it here as text if any
  • [*] I have reproduced the issue with at least the latest released version of superset
  • [*] I have checked the issue tracker for the same issue and I haven't found one similar

Superset version

superset-0.20.4

Expected results

Want to run superset on http://127.0.0.1:8088/analytics/ , currently it runs on http://127.0.0.1:8088. Although, I understand this is not a bug but there should be a way in configuration file (config.py) to change url_prefix. When I am moving my superset installation to Production, I would prefer to keep it behind the proxypass of apache and not expose it directly on /.

Actual results

I couldn't find any option in config file to change the url_prefix in flask.

Steps to reproduce

Its a default setting. Need an option in config file or a procedure to add url_prefix.

Thanks

inactive

Most helpful comment

Hi all, i have been working on the same issue for a while and i have some suggestions,
like @sshcherbakov mentioned the only way to workaround is to rely on reverse proxy configuration which is not very appropriate, you will end up with a configuration like this:

location ~ ^/(users|userstatschartview|roles|permissions|permissionviews|viewmenus|logout|login|logmodelview|dashboardasync|databaseasync|csstemplateasyncmodelview|druid|druidclustermodelview|druiddatasourcemodelview|csstemplatemodelview|csvtodatabaseview|sliceaddview|dashboard|chart|databaseview|tablemodelview|queryview|annotationlayermodelview|annotationmodelview|lang)/ {
            auth_basic off;
        rewrite ^/(.*) /MY_PREFIX/$1 permanent;
            proxy_pass http://MY_ADDRESS:MY_PORT;
            proxy_set_header Host $host;
    }

as you can see you need to match all the hard codded path that are being redirected to the default root context ('/'). i will say this is ugly. There might be some further modifications in these paths which make the maintenance not very interesting.
1- The first solution i'm proposing is to make all the routes uniform by adding /superset, then you can rewrite the URL in nginx configuration like this:

location ^~ /MY_PREFIX/ {
            auth_basic off;
            proxy_pass http://MY_ADDRESS:MY_PORT;
            proxy_set_header Host $host;
    }

    location ^~ /superset/ {
            auth_basic off;
        rewrite ^/superset/(.*) /MY_PREFIX/superset/$1 permanent;
            proxy_pass http://MY_ADDRESS:MY_PORT;
            proxy_set_header Host $host;
    }

this is working well as long as all the paths start with /superset, but because there are many other paths that does you have to match all of them like mentioned above. Even if it will still be hard coded at least it will make the workaround much easy to maintain and reliable.

2- And the second which might be less easier but good for long term is to define a global parameter configuration in the config file like (URL_PREFIX), which should be added as base path to all the routes, then get rid of the hard coded URL.
But even if there is still hard codes like redirects make sure to add the base path to it.
This issue is been open for 2 years now and i really hope it can be fixed.
Also @joharohl has done a pretty job with this pull request https://github.com/apache/incubator-superset/pull/1866/files and i think it deserve to be reviewed, applied to all hardcoded, and merge to the master branch.

Thanks.

All 21 comments

I meet the same problem

:+1:

@geekSnails +1

+1

basically, no

https://github.com/apache/incubator-superset/pull/1866/

This PR was closed after 3 months... Sad.

Hi,

I am also having the same issue. I tried to fix it using Blurprints but superset doesn't seem to take into consideration blueprints with url_prefix.

The main reason the need for me is I am trying to deploy superset on AWS Lambda on a serverless environment and since AWS API Gateway adds a stage name like '/dev' all the links are broken. I am able to get to the login page but most of them doesn't work because it seems it's trying to access resources at "/" but API Gateway puts all of them at "/dev".

Any other way or do we need to modify all the static URL's?

Can you help me to see if someone can get Blueprints working on superset with url_prefix option?

Thanks

Just a feedback here.
This is a shame that such basic functionality doesn't work because of the code quality (and subsequent difficulty to fix).
The workaround in the PR #1866 is ugly and doesn't really work. It relies on the reverse proxy config (which might not be appropriate in some cases) and still does not solve the issue of Superset running on the default root context path ('/').
:(

Hi all, i have been working on the same issue for a while and i have some suggestions,
like @sshcherbakov mentioned the only way to workaround is to rely on reverse proxy configuration which is not very appropriate, you will end up with a configuration like this:

location ~ ^/(users|userstatschartview|roles|permissions|permissionviews|viewmenus|logout|login|logmodelview|dashboardasync|databaseasync|csstemplateasyncmodelview|druid|druidclustermodelview|druiddatasourcemodelview|csstemplatemodelview|csvtodatabaseview|sliceaddview|dashboard|chart|databaseview|tablemodelview|queryview|annotationlayermodelview|annotationmodelview|lang)/ {
            auth_basic off;
        rewrite ^/(.*) /MY_PREFIX/$1 permanent;
            proxy_pass http://MY_ADDRESS:MY_PORT;
            proxy_set_header Host $host;
    }

as you can see you need to match all the hard codded path that are being redirected to the default root context ('/'). i will say this is ugly. There might be some further modifications in these paths which make the maintenance not very interesting.
1- The first solution i'm proposing is to make all the routes uniform by adding /superset, then you can rewrite the URL in nginx configuration like this:

location ^~ /MY_PREFIX/ {
            auth_basic off;
            proxy_pass http://MY_ADDRESS:MY_PORT;
            proxy_set_header Host $host;
    }

    location ^~ /superset/ {
            auth_basic off;
        rewrite ^/superset/(.*) /MY_PREFIX/superset/$1 permanent;
            proxy_pass http://MY_ADDRESS:MY_PORT;
            proxy_set_header Host $host;
    }

this is working well as long as all the paths start with /superset, but because there are many other paths that does you have to match all of them like mentioned above. Even if it will still be hard coded at least it will make the workaround much easy to maintain and reliable.

2- And the second which might be less easier but good for long term is to define a global parameter configuration in the config file like (URL_PREFIX), which should be added as base path to all the routes, then get rid of the hard coded URL.
But even if there is still hard codes like redirects make sure to add the base path to it.
This issue is been open for 2 years now and i really hope it can be fixed.
Also @joharohl has done a pretty job with this pull request https://github.com/apache/incubator-superset/pull/1866/files and i think it deserve to be reviewed, applied to all hardcoded, and merge to the master branch.

Thanks.

@pandamien I've attempted your first option to configure as below;

location ~ ^/(users|userstatschartview|roles|permissions|permissionviews|viewmenus|logout|login|logmodelview|dashboardasync|databaseasync|csstemplateasyncmodelview|druid|druidclustermodelview|druiddatasourcemodelview|csstemplatemodelview|csvtodatabaseview|sliceaddview|dashboard|chart|databaseview|tablemodelview|queryview|annotationlayermodelview|annotationmodelview|lang)/ {
            auth_basic off;
        rewrite ^/(.*) /dashboard/$1 permanent;
            proxy_pass http://MY_ADDRESS:MY_PORT;
            proxy_set_header Host $host;
    }

but i just end up with endless redirect as;

http://wesbsite/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/dashboard/login/

Have I missed something obvious? This is with NGINX

Theres an interesting looking option on Stackoverflow which I'm trying to set up

Hi,

I wanted to run 'Superset' in complete serverless environment on AWS. Basically, want to run superset on AWS Lambda.

I have tried different methods recommended and all of them resulted in some or other place break of functionality. Eventually what i did was the below to make it work:

1) In config.py i have added another configuration variable and used this variable in locations where redirect or appbuilder.add_link has been used.
2) In templates folder there are places where directly '/superset/' has been used. So, even if i did first step right, the templates are not rendering in right way. So, i have to go and change the template as well (As of now I have hard-coded this. I need to make it configurable)
3) In front-end i have added a file called config.ts and I have used this config in locations wherever redirect was done in front-end. This has fixed up all my front-end links.
4) Only thing remaining for me was fixing "Upload CSV to Database" Link. When we click this link and enter the data, since Lambda doesn't allow any writes i tried to write to /tmp - but since we don't know whether the next request is going to be served by same lambda or not... so this is an issue as of now. The way I am planning to fix this is to write the files to s3 instead of local folder. I am still figuring out a way to do this.

After above all are done, I have used AWS Aurora Serverless as my metadata database. This way I don't even need to pay for the database since Aurora is MySQL version.

Hope this helps. Once i fix up the remaining this, I need to check how to make this available to all.

-- No more nginx or other links. We don't even need gunicorn in this setup.

Thanks
Kiran

@kirankumarpv I'd be very interested in an update on this as I was about to attempt the same thing.

@kirankumarpv I'd be very interested in an update on this as I was about to attempt the same thing.

All the fixes has been done and tested. Everything working fine on Local. On AWS Lambda "Upload CSV to Database" is not working because it cannot write to /static folder.

For my use case, I don't really need to use "upload CSV to Database" function. So, I am not going to put effort to fix it as of now. But, ideally if you are running locally on any server on any endpoint other than '/', my fix should perfectly work fine.

Hi,

Can anyone help me to make a pull request for this particular issue so that i can merge the code?

Thanks

I am facing the same problem.
This is due to absolute redirection (not using url_for)
example: https://github.com/apache/incubator-superset/blob/master/superset/__init__.py#L191
Workaround: wsgi middleware to catch redirection response and dirty patch Location HEADER
Sorry, no time immediately to propose a PR

I am facing the same problem.
This is due to absolute redirection (not using url_for)
example: https://github.com/apache/incubator-superset/blob/master/superset/__init__.py#L191
Workaround: wsgi middleware to catch redirection response and dirty patch Location HEADER
Sorry, no time immediately to propose a PR

I have tried that. Using wsgi middleware to catch redirection reponse and dirty patch location HEADER but that results in sometimes application going to indefinite multiple redirects

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

Hi Kirankumar,

I was seeing you comments on your success of implementing Superset on AWS Lambda. I was struggling to get any literature for doing the same. Can you please guide me to do this.

Regards,
Chethan G Puttaswamy

Can this be reopened as a feature request? we would like to use it but not able to run it on a subpath /superset makes it impossible to use it in our environment. I have been able to run it using the helm chart but not being able to run a subpath makes it a non starter for me.

Hi Team,

Do we have fix for this issue in latest 0.36 version?

Thanks.

Hello @thammaneni,
I don't think so since there is still "hard" redirections (path vs url_for)
Example : https://github.com/apache/incubator-superset/blob/master/superset/views/core.py#L496
++ / Ali

Was this page helpful?
0 / 5 - 0 ratings