3

I've found here the following architecture:

enter image description here

I've understood that single-page web application requests static resourses to CDN and API resources to APIM. Is the browser contacting two different FQDN (for example: www.site.it and www.api.site.it)?

In order to access to with a single FQDN, could I move the CDN in front of the APIM? Could I achieve it with CDN rules?

Could I help me?

enter image description here

Michel Foucault
  • 1,724
  • 3
  • 25
  • 48

2 Answers2

3

This should be possible with routing rules which are available in the Verizon Premium Tier of Azure CDN.

The rules that you would need to configure would be a URL Rewrite for requests with a /api path and the Bypass Cache rule for any endpoints that may return sensitive/user-specific data.

Also, note that you optimum performance of the APIs that return dynamic content, you would want to deploy APIM to multiple regions as well (and the APIs behind it as well, functions in this case).

Azure Front Door is another option that you could consider which has a host of other features available to you.

PramodValavala
  • 6,026
  • 1
  • 11
  • 30
  • So, do You think that it is a good practice? Are there others solutions? – Michel Foucault Apr 07 '20 at 15:47
  • 1
    Well, a CDN is more or less like a reverse proxy, so nothing wrong in using it as such I suppose. And on the plus side, you could even cache common API requests that are common to all users. This would essentially be a plus when you don't have an APIM instance close to each region. [Azure Front Door](https://learn.microsoft.com/en-us/azure/frontdoor/front-door-overview) is another option that you could consider with a host of other functionality like SSL Termination. – PramodValavala Apr 07 '20 at 15:51
  • 1
    Do make sure not to cache user-specific data or any dynamic data for that matter – PramodValavala Apr 07 '20 at 15:53
  • My solution is an interpreation of first schema (provided by Microsoft). So, I thought of using the CDN as an entry point. The answer di @PramodValavala-MSFT has been very useful – Michel Foucault Apr 07 '20 at 16:22
  • Hey @MichelFoucault did you succeed implementing this? I've tried your proposed setup with MSFT CDN: 1.client sends http request of function app to CDN endpoint; 2.CDN EP redirects this to APIM function app; 3.function app responds sending a file back with return FileContentResult. This redirect works but CDN doesn't cache the file of the function. CDN Settings: Caching rule = cache every unique URL. I tried Standard rule engine redirect 307 and 301, 301 caches according to MSFT CDN docs. Do you input the APIM address as the CDN EP origin hostname? Thank you – Sergio Solorzano May 15 '21 at 14:47
  • Sorry I didn't try. The question was a theorycal curiosity. – Michel Foucault May 15 '21 at 18:17
  • This does not work, since the destination URL of an URL rewrite has to be relative and has to start with a '/'. – michidk Mar 24 '22 at 13:37
0

This can be achieved by creating a second origin & origin group (create the first one for the origin you already have) for the API with a custom type to point to the URL of the API. Then add a URL rewrite rule with an "Origin Group Override" action to the rules engine and choose your API origin (you might also want to enable the "Cache expiration" action to bypass cache).

michidk
  • 351
  • 1
  • 4
  • 18