unit icon indicating copy to clipboard operation
unit copied to clipboard

Map static content url to some folder

Open smtalk opened this issue 4 years ago • 5 comments

Currently:

{
    "match": {
      "uri": "/django/static/*"
    },
    "action": {
      "share": "/home/admin/domains/domain.com/public_html/portfolio-project/media/"
    }
  },

For https://domain.comdjango/static/images/weide.jpg would look for files in that folder + uri, in this case /home/admin/domains/domain.com/public_html/portfolio-project/media/django/static/images/weide.jpg instead of just /home/admin/domains/domain.com/public_html/portfolio-project/media/images/weide.jpg

May we have something like:

    "match": {
      "uri": "/django/static/*"
    },
    "action": {
      "share": "/home/admin/domains/domain.com/public_html/portfolio-project/media/",
      "map": true
    }
  },

Which would solve the problem and map /django/static/ to that folder? Alternatively, I guess something similar to nginx alias directive may do the trick, but I'm not sure when/if it's planned?

smtalk avatar May 25 '21 08:05 smtalk

@smtalk We're on the feature of supporting variables in the "share" option. such as:

{
     "share": "/data/www$uri"
}

It will use the value from "share" as the file path.

hongzhidao avatar May 25 '21 09:05 hongzhidao

@hongzhidao but wouldn't it just try to append $uri to that path? The problem is that we'd like to serve domain.com/images from /path/to/project_images for example, and now it'd try to look in /path/to/project_images/images instead of just /path/to/project_images due to $uri always appended to the static path by default.

smtalk avatar May 25 '21 09:05 smtalk

$uri always appended to the static path by default.

yes, the current version works the way.

as I mentioned, in the future the rule will be changed. the path to find becomes the value from the "share" option. is that the way you want it?

hongzhidao avatar May 25 '21 09:05 hongzhidao

@hongzhidao yes, I think I just misunderstood your first message :) Value from share is what we're looking for. Thanks!

smtalk avatar May 25 '21 10:05 smtalk

@smtalk we also plan to support regex named capture variables, it seems that's what you want.

{
    "match": {
      "uri": "/django(?<alias_uri>/static/*)"
    },
    "action": {
      "share": "/home/admin/domains/domain.com/public_html/portfolio-project/media$alias_uri"
    }
  },

hongzhidao avatar May 25 '21 10:05 hongzhidao