In this article I will explain a way to store your sourcemaps for all your PCFs in a safe and cost efficient way. We will be using an Azure Storage Account, an Azure Function, CloudFlare DNS and CloudFlare Access.
First we need to create a storage account dedicated to our sourcemaps in Azure. You can follow the steps from Microsoft Docs. We can create a blob container named sourcemaps.
Then we need to create an Azure Function that will "control" access to our sourcemaps. You can follow the steps from Microsoft Docs.
We can create a Function called PCF with the following content:
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.IO;
namespace Sourcemaps
{
public static class PCF
{
[FunctionName("PCF")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "PCF/{name}/{version}/{file}")] HttpRequest req,
[Blob("sourcemaps/{name}/{version}/{file}", FileAccess.Read)] Stream myBlob,
string name,
string version,
string file,
ILogger log)
{
if (myBlob == null)
{
return new BadRequestResult();
}
using MemoryStream ms = new();
await myBlob.CopyToAsync(ms);
return new FileContentResult(ms.ToArray(), "application/octet-stream"); ;
}
}
}We created a function because we can configure it's firewall to only allow access from CloudFlare. We can find more information on how to configure the access restrictions on the Microsoft Docs. Also the list of CloudFlare IPs to configure can be found here.
Another important step is to configure our custom domain in our Azure Function. Some information can be found here.
I have the following DNS records for the sourcemaps.xrm.al subdomain:

And also I have the following CloudFlare Access rule for my website:

A unauthenticated user will see the following if they try accessing the sourcemaps (ex. this):

If you enter one of the emails configured in CloudFlare Access then you can see the sourcemaps and can debug your production code by seeing the original (hopefully Typescript) code.
Pro Tip: If you are generating the sourcemaps for your PCFs as in my other article you can add a step in your Release Pipeline similar to the following:

The BUILDCOMMITID variable is being set in the first PowerShell Script Step.