scyllagroup / UmbracoFlare

This project aims to provide a basic level of service integration between Cloudflare and the open-source ASP.NET CMS Umbraco.
https://www.umbracoflare.com/
Creative Commons Attribution Share Alike 4.0 International
18 stars 3 forks source link

7.10.4 - Something went wrong getting the purge cache response back #14

Open brichardson1991 opened 5 years ago

brichardson1991 commented 5 years ago

7.10.4 Whenever clearing the cache I get the following back in my logs

ERROR UmbracoFlare.ApiControllers.CloudflareApiController - Something went wrong getting the purge cache response back. The url that was used is https://api.cloudflare.com/client/v4/zones/zoneid/purge_cache. The json that was used is {"files":["test.domain.co.uk/https://test.domain.co.uk/"]}. The raw string value is {"files":["test.domain.co.uk/https://test.domain.co.uk/"]}

markadrake commented 5 years ago

Yep, the URL is not correct. Thanks for the report @brichardson1991. Looking into it now.

markadrake commented 5 years ago

We'll need to look at this MakeFullUrlWithDomain code, after stripping that out I now have a working UmbracoFlare in the backoffice. I wonder what's changed and what versions of Umbraco this has changed for. I'll bring it up to the team and get something pushed out soon.

https://github.com/scyllagroup/UmbracoFlare/blob/7c68fc9fa7c3cc0b97c90c9dd6c0c37df78c1aab/UmbracoFlare/Manager/UmbracoFlareDomainManager.cs#L127

In the meantime, if you'd like to fix it locally for your site I updated the following lines of code:

        public List<string> GetUrlsForNode(IContent content, bool includeDescendants = false)
        {
            List<string> urls = new List<string>();

            string url = UmbracoContext.Current.RoutingContext.UrlProvider.GetUrl(content.Id, true);

            urls.AddRange(UrlHelper.MakeFullUrlWithDomain(url, RecursivelyGetParentsDomains(new List<string>(), content)));
            urls.AddRange(UmbracoContext.Current.RoutingContext.UrlProvider.GetOtherUrls(content.Id));

            if(includeDescendants)
            {
                foreach(IContent desc in content.Descendants())
                {
                    urls.Add(UmbracoContext.Current.RoutingContext.UrlProvider.GetUrl(desc.Id, true));
                    urls.AddRange(UmbracoContext.Current.RoutingContext.UrlProvider.GetOtherUrls(desc.Id));
                }
            }

            return urls;
        }

And updated it to (from memory):

        public List<string> GetUrlsForNode(IContent content, bool includeDescendants = false)
        {
            List<string> urls = new List<string>();

            urls.Add(UmbracoContext.Current.RoutingContext.UrlProvider.GetUrl(content.Id, true));
            urls.AddRange(UmbracoContext.Current.RoutingContext.UrlProvider.GetOtherUrls(content.Id));

            if(includeDescendants)
            {
                foreach(IContent desc in content.Descendants())
                {
                    urls.Add(UmbracoContext.Current.RoutingContext.UrlProvider.GetUrl(desc.Id, true));
                    urls.AddRange(UmbracoContext.Current.RoutingContext.UrlProvider.GetOtherUrls(desc.Id));
                }
            }

            return urls;
        }

This may not be the final solution of course. I suspect one of the many minor updates since 7.4 / 7.5 has normalized how URLs are coming back.