Serve dashboards with a prefix
mao-liu opened this issue · 3 comments
Hi,
I recently tried to collect the several web services under one Apache server, one of them is the dashboards server. Each of these services run on a different localhost port, and Apache acts as the reverse-proxy to direct different URLs to different ports based on the prefix.
e.g.
my.domain.com/jupyter --> http://127.0.0.1:9500/jupyter
, jupyter hub serving on localhost:9500/jupyter
my.domain.com/jenkins --> http://127.0.0.1:8080/jenkins
, jenkins serving on localhost:8080/jenkins
...`
I cannot find a way to specify a prefix for the dashboards server. I can only get it to serve on http://host:port
, whereas I would like to be able to serve at http://host:port/prefix
.
My initial dig into this points to some changes required in the templates, particularly the way /css
and /components
are linked in the templates.
Is this an easy thing to implement? I am not very familiar with node/express, but will be happy to have a go at a pull request.
Cheers,
@ch41rmn We'd love a PR if you're willing to tackle this.
You are correct that the dashboard server is not currently relocatable under different paths. I'm pretty certain there is no major impediment preventing it, just a matter of finding all the spots that might break. The ones that come to mind are:
- The templates, as you pointed out. These should use relative path references wherever possible. If they can't they'll need to read a base URL config option that has to be defined.
- The express router. The root path needs to be made configurable via a base URL option. Hopefully all of the changes should be in app.js, either by adding the base URL value to all of the
app.use()
calls or by defining a new root router and tacking all of the exiting paths onto it. (ref: http://bulkan-evcimen.com/using_express_router_instead_of_express_namespace.html) - Any places that generate links, like https://github.com/jupyter-incubator/dashboards_server/blob/792dc792cfa5358baede419b8918dff30dd1db16/routes/auth-routes.js#L26 (though that one is already driven by configuration, so might not need any work.)
@jhpedemonte, @dalogsdon can you think of other spots that would need updating?
I think those mentioned by @parente are the main points.
- For templates (mainly the listing view but possibly others) we are using Handlebars. You will probably need to pass the prefix when rendering. In the template, if a variable isn't set, it will resolve to an empty string.
- For the router, I'd vote for a root router. That way it's only in once place and you don't have to think about the prefix in the child routes.
- The config parameter
PUBLIC_LINK_PATTERN
will need to include the prefix. See config.json. The config uses Hjson