-
Notifications
You must be signed in to change notification settings - Fork 42
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
Create an Asset Link URL Resolver #193
Comments
Update. I created a middleware as follows:
Registered in Startup.cs as follows. The two key points are the registration of the AssetLinkMiddleware and the Asset link controller routing.
My ProjectOptionsBase:
My appsettings.config that maps to my project options base:
|
So let me summarize the requirements and let's see if I understand the problem correctly:
Solutions: Since Kontent doesn't allow mapping custom domains to the CDN servers (which is something that you can request in the roadmap) you'd need to create a proxy/middleware that would translate arrt.org links to CDN links or that would serve the PDFs directly from the arrt.org domain (by downloading the content from the CDN first - you'd probably lose some performance advantage here). It is possible to bypass all this by creating a wrapping content type called "PDF" with fields like "Name", "URL slug", and "Asset". This way, you can easily render the rich text with correct links + query PDF assets by "URL slug" (which could be extracted from a route and passed to the controller). Similarly, if (4) is not true and you want to serve the PDF from where they already are you can create a custom content type called "PDF" with "Name" and "URL" elements and link them from your rich text fields. One more question for you: do you want to preserve the current URLs of the assets? Because if your current route pattern is not deterministic/predictable this can be potentially quite complicated. |
The middleware I posted has actually solved this issue for us. (FYI, I updated it above since it had a bug with binary data, made it target only text/html now and that seems to fix it). What it does is the following:
preview-assets-us-01.kc-usercontent.com:443 It then remaps the that to this URL: localdevwwwcore.arrt.org/Assets This makes the following URL: Turn into this: Then our AssetsController.cs:
Code of GetKenticoAsset:
I hope this make sense what I'm asking for. Either a Asset Link resolver that doesn't make me write all this code to re-write the HttpContext.Response.Body or something like my alternative solution (shown below). Here is a mockup of a proposal for Alternative Solution # 1 above (Specify the URL link in Kentico.Ai portal to define this information?) So when the JSON comes back it's already altered to go to the correct place. We would then just go construct the CDN url and fetch it with our own HttpClient. Asset Url Rewrite is the box I mocked up in the below image :-) I really like the concept of the Alternative Solution # 1 I proposed as it requires almost no changes in your API's, just the URL's that are currently being surfaced from your API. Least amount of code changes I would think doing that route. |
BTW, I updated the code in my replies above, so please re-review. |
Here is information that might be helpful for Alternative solution # 2 (Using DNS CNAMES to point to your Fastly CDN): https://docs.fastly.com/en/guides/working-with-domains If you surfaced a way to map our domain to your CDN in app.kontent.ai settings page perhaps that is another way to solve this. Then we could use your CDN servers (which would be ideal) and we still would get the benefit of the content appearing to come from our domain (assets.arrt.org for example) |
Hi, I did some investigation on how other customers build their applications with custom domains for assets. They mentioned using a CDN and setting the rules for caching to save some cross-site requests and traffic. At the moment, building a middleware service, as you did, would be the best way to do asset white labeling. By the way, since there are already some requests for this feature, we've added it to considering section on our roadmap. You can vote there for features that are important for you as well as submit your own ideas. Best regards, Lukas Turek |
@lukasturek I tried finding that feature request on your roadmap but couldn't find it. The link appears to be broken. |
I have adjusted the link |
FYI, we had to back out the middleware we were using. I couldn't get it to work 100% of the time (weird blank page issue randomly) when used in conjunction with Microsoft's response caching middleware :( |
So you're back with the CDN links, right? We have no immediate plan to address this, we first need to stabilize the v14 release. I guess we can take a look at this one then. Could you perhaps draft a PR addressing the issue here? It might speed up things. (Sorry for my late responses...We just had a baby so I was busy changing dipers :)) |
Congrats! Yeah we are using the cdn links now. You want a pull request containing what? |
thanks! :) PR of the suggested "Asset Link Url Resolver"...if that's what would help you solve the issue (e.g. replace the current middleware). We can at least start iterating from there to see if it's a way to go. |
So I played with this a bit more and I can't repro it anymore (atleast locally). It may have something to do with our hardware load balancer as well. So, more investigation is needed. |
ok. I'll leave this open and wait for more input. |
Motivation
Our current website serves up many PDF files. They can be easily found using google.
Such as this: https://www.google.com/search?sxsrf=ALeKk032G0vKTmeNlvlepndVXztTtzAJpg%3A1582830339114&source=hp&ei=AhNYXrCKN5nN0PEP7eyykA8&q=ARRT+rules+and+regulations&oq=ARRT+rules+and+regulations&gs_l=psy-ab.3..0.8034.11005..11150...2.0..0.209.4317.0j24j2......0....1..gws-wiz.....10..35i39j0i131j35i362i39j0i10j0i22i30j0i22i10i30.0Ws3sH2JO30&ved=0ahUKEwiwk9zAtvLnAhWZJjQIHW22DPIQ4dUDCAg&uact=5
You will see that one of the links is this: https://www.arrt.org/docs/default-source/governing-documents/arrt-rules-and-regulations.pdf?sfvrsn=3f9e02fc_42
As you can see it is being served up from our domain.
However, it seems that with Kentico Kontent we do not have flexibility of defining an Asset Link URL Resolver.
We can create Content Item Resolvers, but not Asset Link Resolvers.
Instead what is being surfaced right now in the above example might be something like this:
https://preview-assets-us-01.kc-usercontent.com:443/406ac8c6-58e8-00b3-e3c1-0c312965deb2/ba8df0e1-69da-44f4-b197-9aceafb39979/arrt-rules-and-regulations.pdf
This has some negative ramifications for our business as follows:
We need the ability to define an asset link resolver in the Kentico client builder registration.
Right now the approach we are attempting is the following:
Is this the best way to do it for now?
Not sure on performance or if those kc-usercontent.com links can dynamically change and we need to define a whole list of potential CDN servers?
Proposed solution
Introduce Asset Link Url Resolver, much like the Content Item resolver you already have.
Alternative solutions:
The text was updated successfully, but these errors were encountered: