Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created September 7, 2019 16:15
Show Gist options
  • Save adamdriscoll/a1751599c8e55db3b54da1944fb00825 to your computer and use it in GitHub Desktop.
Save adamdriscoll/a1751599c8e55db3b54da1944fb00825 to your computer and use it in GitHub Desktop.
JavaScript Controller Asset Endpoint
[Route("{asset}")]
public IActionResult Index(string asset)
{
var filePath = AssetService.Instance.FindAsset(asset);
if (filePath == null)
{
Log.Warn($"Unknown element script: {asset}");
return StatusCode(404);
}
if (filePath.StartsWith("http")) {
return Redirect(filePath);
}
if (!System.IO.File.Exists(filePath))
{
Log.Warn($"Static file [{filePath}] does not exist.");
return StatusCode(404);
}
return PhysicalFile(filePath, "text/javascript");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment