3

I would like to have https://example.com as the custom domain for the Azure CDN I have setup, and https://example.com/api as the rest api endpoint to catch all of the calls from my SPA to the back-end .Net Core Web API providing the data.

How can I setup a custom domain on an App Service to serve the https://example.com/api and use the same custom domain for the Azure CDN to serve all of the front-end SPA web pages?

Right now, I have the custom domain configured for the App Service only, but I would like to move the front-end SPA to an Azure CDN to free up as many resources as possible for the Web API.

Thank you in advance, any direction would be greatly appreciated.

Steven Pfeifer
  • 345
  • 4
  • 11
  • Hi , if you want to add a custom domain for your Azure CDN , pls refer to : https://learn.microsoft.com/en-us/azure/cdn/cdn-map-content-to-custom-domain – Stanley Gong Aug 27 '19 at 01:28
  • Hi thanks for the reply, but I want the same custom domain for both my Azure CDN and app service, this only shows how to add a custom domain to the Azure CDN – Steven Pfeifer Aug 27 '19 at 01:55
  • Weclome ! As far as I know it is impossible to assign one domain to different services . So are you solving CORS issues here ? If so , this doc maybe helpful for you : https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-rest-api – Stanley Gong Aug 27 '19 at 02:35
  • 1
    you should try solving this problem using subdomains: `api.example.com` for your api and `example.com` for your spa as it is will be the domain visible by your users. – Thomas Aug 27 '19 at 09:27

2 Answers2

2

Unfortunately, it's impossible to add the same custom domain in two different public services since the CNAME record only can be used when there are no other records on that name when you need to add custom domains to your CDN endpoint and App service via a CNAME or A DNS record. See CNAME record wiki.

In this case, you could add a custom domain to your Azure CDN endpoint via a CNAME DNS record following this tutorial, but you need to create a subdomain like subdomain.example.com instead of the root domain example.com, then add the subdomain to the custom domains of Azure CDN endpoint.

Nancy
  • 26,865
  • 3
  • 18
  • 34
2

You can introduce another resource like Azure Front Door that can act as a proxy and hides both the CDN and your App Service behind a single domain.

Front Door allows you to configure routing rules so that requests for /api get routed to the App Service and requests for static assets get routed to the CDN.

You can then set your DNS CNAME to Front Door and all requests will be sent there rather than directly to the CDN or your App Service.

This gives you the advantage of not needing to worry about CORS, because from an outside perspective everything is coming from the same domain.

It also has additional benefits like allowing you to configure request throttling, SSL termination and global load balancing to name a few.

Steve
  • 2,205
  • 1
  • 21
  • 28
  • Wow I never noticed this service, thank you! Would front-end SPA files being served through a CDN behind Azure Front Door count towards the bill as Front Door outbound data transfers? Just because I'm a little confused on the pricing – Steven Pfeifer Aug 27 '19 at 17:07