Skip to content
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

feat: takes into account when statics not in host_url root #22

Closed
wants to merge 1 commit into from

Conversation

ybenitezf
Copy link

@ybenitezf ybenitezf commented Jun 5, 2021

I added some tests with pytest, think I included all the cases, let me know if i need to include more examples

Closes #21

@ybenitezf ybenitezf marked this pull request as ready for review June 5, 2021 22:23
@nickjj
Copy link
Owner

nickjj commented Jun 6, 2021

Hi,

Thanks, I haven't gotten a chance to test it locally but does this work when FLASK_STATIC_DIGEST_HOST_URL is None which is the default when you don't set it? Also, for parse_digest_host_url, was it necessary to return a tuple there? What happens if you return everything together which is then used in _prepend_host_url?

@ybenitezf
Copy link
Author

... Also, for parse_digest_host_url, was it necessary to return a tuple there? What happens if you return everything together which is then used in _prepend_host_url?

I just wanted to test this separately. Also, It seemed to me that I should not mix parse_digest_host_url with the code in the class. But yea, i could do as you say, let me know if a fix is needed for this.

@nickjj
Copy link
Owner

nickjj commented Jun 7, 2021

Will have to think about that one a bit. Just replying to acknowledge your response. Since it's the work week now I'm a little slammed, but I want to let you know this will for sure get merged in 1 way or another.

@ybenitezf
Copy link
Author

@nickjj ¿any progress with this?

Copy link
Owner

@nickjj nickjj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've left a few comments. Let me know what you think.

def parse_digest_host_url(host_url_prefix):
"""
Detect if host_url_prefix contains a path element and returns a tuple with
the elements (host_part, path_part), for example for
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you re-word this line to be:

the elements (host_part, path_part), for example:


host_url_prefix = "https://cdn.example.com/myapp/some/path/"

This function should return:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this line to:

This function will return results such as:

host_url_prefix = "https://cdn.example.com/myapp/some/path/"

This function should return:
('https://cdn.example.com', "/myapp/some/path/")
Copy link
Owner

@nickjj nickjj Jul 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this line into these lines:

# When there's no path:
("https://cdn.example.com")

# When there's a path:
("https://cdn.example.com", "/my/custom/path/")

@@ -84,3 +86,28 @@ def static_url_for(self, endpoint, **values):
merged_values.get("filename"))
else:
return flask_url_for(endpoint, **merged_values)


def parse_digest_host_url(host_url_prefix):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this function to _parse_digest_host_url since it's private?

@@ -46,8 +46,10 @@ def _load_manifest(self, app):
return manifest_dict

def _prepend_host_url(self, host, filename):
return urljoin(self.host_url,
"/".join([self.static_url_path, filename]))
parts = list( # removing empty strings
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance we can write rewrite this and the line below it to be a more clear on what it does?

@@ -0,0 +1,39 @@
from flask_static_digest import parse_digest_host_url
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on replicating all of these tests without using pytest, following the same patterns used in the existing test suite?

@nickjj
Copy link
Owner

nickjj commented Jul 16, 2021

I'm beginning to think this PR along with FLASK_STATIC_DIGEST_HOST_URL might not even be needed due to a new recent discovery. I always set Flask's static_url_path to "" in development but it just dawned on me that you could very likely set that to https://cdn.example.com/whatever/you/want" and Flask will prefix your URLs with that.

That completely negates needing FLASK_STATIC_DIGEST_HOST_URL.

What do you think?

@ybenitezf
Copy link
Author

I'm beginning to think this PR along with FLASK_STATIC_DIGEST_HOST_URL might not even be needed due to a new recent discovery. I always set Flask's static_url_path to "" in development but it just dawned on me that you could very likely set that to https://cdn.example.com/whatever/you/want" and Flask will prefix your URLs with that.

That completely negates needing FLASK_STATIC_DIGEST_HOST_URL.

What do you think?

It depends on if it works, have you tested ? i don't have time right now, if u think that work ok, u should update the README.md and close this PR.

@nickjj
Copy link
Owner

nickjj commented Jul 16, 2021

I haven't tested it yet but I will in the next couple of days.

If it works I'll update the readme and ship a new version with that option removed along with adding new docs to go over how to do the same thing with Flask's built in static_url_path.

@nickjj
Copy link
Owner

nickjj commented Jul 16, 2021

Nope, it doesn't work. static_url_path requires a URL that starts with a / so putting in a hostname with a protocol doesn't work.

Which means the option and this PR is still going to be a good idea.

@nickjj
Copy link
Owner

nickjj commented May 17, 2024

This has been resolved in: #38

@nickjj nickjj closed this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Statics no in FLASK_STATIC_DIGEST_HOST_URL root
2 participants