taskwarrior-web icon indicating copy to clipboard operation
taskwarrior-web copied to clipboard

no way to set base_uri esp. for static content (css/js)

Open droopy4096 opened this issue 10 years ago • 3 comments

I saw issue #20 being closed couple of years ago, however instead of resurrecting it I wanted to clarify that at present - it's pretty difficult to run task-web alongside with anything else if you don't want to start opening a lot of ports.

I have tried various "solutions" from the google finds to make task-web run behind proxy with it's URI path changed from "/" to "/task/" however I can only get dynamic portion of task-web to cooperate - static still clings to "/" and I found no way of changing that (well I'm not that good with ruby and RoR stuff...). If there's presently a way to change application's base_uri - can it please be clearly documented someplace? Existing Wiki page outlines how to set up "hacked up" proxy which would be changing HTML content etc. which in turn limits choices of proxies to use and requires specific capabilities to be present (like in case with Wiki solution requires apache-2.4 whereas target system can run either nginx or apache-2.2, neither was very cooperative in hacking up task-web's html into submission).

droopy4096 avatar Sep 17 '13 20:09 droopy4096

Well, i can't actually comment on the "run task-web alongside with anything else" put running task-web behind a proxy, especially with SSL in mind, which breaks static content like CSS and JS due to using absolute paths.

I don't have a proper solution for this problem either, but IMHO removing any and all absolute paths from source would benefit us all as all modern web browser should be smart enough to server content with a relative path using the current server/protocol.

@droopy4096

As you mentioned, @jagipson has filled a bug report and provided a "hack" for Apache almost a year ago to get this working.

Here is a solution for thous who need or better yet want to use nginx over Apache, using nginxs sub_filter which is the equivalent to Apaches ProxyHTMLURLMap.

Important Node: You will need the HttpSubModule to get this to work, which requires nginx to be compiled with the "--with-http_sub_module" option, nginx v1.4.3 installed from the official nginx CentOS/Redhead repository includes this module already.

    server {
        listen 443;

        server_name task.domain.com;

        location / {
            # this will replaces all occurrences of 10.0.0.123:5678
            # in absolute paths with the server_name
            proxy_set_header Host $http_host;
            # fixes "302 Moved" redirecting to the http:// version
            # if you are using basic-auth in your .taskrc
            proxy_redirect http://$1 https://$1;
            # this will proxy all requests to https://server_name to your
            # local task-web running at IP 10.0.0.123 on port 5678 
            proxy_pass http://10.0.0.1:5678/;
            # this will replace all instances of http:// in the task-web HTML with https://
            sub_filter http:// 'https://';
            # replace all instances of http:// with https:// and not just the first
            sub_filter_once off;
        }
    }

Markup:

  1. You access your task-web using https://task.domain.com pointing to your nginx
  2. proxy_set_header replaces all references of task-web in every absolute path to the local IP with task.domain.com 2.1 e.g http://10.0.0.123:5678/css/... becomes http://task.doman.com/css/... (this still won't do it)
  3. sub_filter replaces all references of http:// in every absolute path with https:// 3.1 e.g http://task.domain.com/css/... becomes https://task.domain.com/css/ (but this does)

Ain't pretty as it's still just a Hack but now you atleast have to different Hacks to choose from.

Cheers

defkev avatar Nov 19 '13 23:11 defkev

UPDATE: If you are using task-web with Basic Authentication enabled (task-web.user and task-web.passwd defined in your .taskrc) than Rack will respond with a "302 Moved" response pointing to http:// after a successful login resulting in a timeout.

Simply add:

proxy_redirect http://$1 https://$1;

to your nginx.conf to redirect all http requests to https.

I have updated the config example in my initial post accordingly.

defkev avatar Nov 20 '13 20:11 defkev

Any idea for configuring nginx for serving from a subpath? I'm trying to serve it from <server>/tasks and <server>/projects but not <server>/ (I would be okay with <server>/task/tasks, <server>/task/projects if that's easier).

I got it working without resources by adding two location paths, one for tasks and one for projects. But I can't figure out how to modify the sub_filter part. What's the original form of the paths I'm trying to match?

hsharrison avatar Sep 18 '14 17:09 hsharrison