-
Notifications
You must be signed in to change notification settings - Fork 27
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
Statics no in FLASK_STATIC_DIGEST_HOST_URL root #21
Comments
Thanks, looks like I'll need to look into this in more detail and come up with a better strategy on joining the url paths. It's this code: def _prepend_host_url(self, host, filename):
return urljoin(self.host_url,
"/".join([self.static_url_path, filename])) Maybe if it changes to: def _prepend_host_url(self, filename):
return urljoin(self.host_url,
"".join([self.host_url, self.static_url_path, filename])) It might work but I noticed while messing around with it in a REPL that it's very picky about having |
I mean, it is not a problem per se, i think the behavior now is correct as it is, Maybe it makes sense to add another variable, def _prepend_host_url(self, filename):
return urljoin(self.host_url,
"".join([self.host_url, self.host_prefix, self.static_url_path, filename])) Doing some tests in the console: host_url = "https://assets.example.com/"
prefix = "myapp"
static_url_path = "static"
filename = "myimg.png"
print( urljoin(host_url, "/".join([prefix, static_url_path, filename])) )
# will print 'https://assets.example.com/myapp/static/myimg.png'
# even adding an aditional /
prefix = "myapp/"
print( urljoin(host_url, "/".join([prefix, static_url_path, filename])) )
# will print 'https://assets.example.com/myapp/static/myimg.png'
prefix = "myapp/someother/folder"
print( urljoin(host_url, "/".join([prefix, static_url_path, filename])) )
# will print 'https://assets.example.com/myapp/someother/folder/static/myimg.png' Would it be okay if I ask you for a PR with that idea? |
The tricky part is when the host_url and / or static_url_path have a trailing or leading I think the current Ideally this would be a backwards compatible change with no change other than now your custom path would get used instead of being stripped out if you happen to use one. If you want to take a shot at a PR that would be great. I would try to test it with the following combos:
Ideally it would work on both Linux and Windows. If you do |
Thanks, yup you are right:
I'll give it a shot |
I'm having the same problem and as far as I can tell, this hasn't been resolved yet. Specifically my issue is that I'm using a Google storage bucket as CDN. Since those always have the format https://storage.googleapis.com/<bucket_name>, there is very little I can do to avoid the subdirectory. |
Hi @Midnighit, yep there's still a pending PR to potentially resolve it. |
Since this PR has been dormant for almost 3 years now: any chance that this could be resolved even if the original author of the PR isn't reacting anymore? As of now I'm resolving it by creating my own CustomFlaskStaticDigest and overriding the original static_url_for method. The workaround is rather crude (strip any potential leading / of the result of url_for if a host url is given) and I would prefer a cleaner solution in flask-static-digest directly. |
Sure, how do you feel about opening a new PR to work towards this? |
I will try. That would be my first time contributing this way with a PR though, so please bear with me. :-) |
Sorry guys, got my hand fulls right now and can not contribute |
It's all good, thanks for getting this started. It's been resolved in: #38 and is published in v0.4.1. |
I have noted that
FLASK_STATIC_DIGEST_HOST_URL
only work's if the statics are put on the root of the CDN, for example in a conventional/normal app, with the statics in thestatic
folder, when i putFLASK_STATIC_DIGEST_HOST_URL='https://assets.example.com/myapp/static/'
an URL forstatic/myimg.png
will behttps://assets.example.com/static/myimg.png
and nothttps://assets.example.com/myapp/static/myimg.png
as intended. So no sharing?I ask in the event that ones needs to share the same CDN host for several app's. I know that the file names will include the hashes and that if two files conflict it means it is the same file, but i wold like to maintain the separation. Any thoughts ?
The text was updated successfully, but these errors were encountered: