Created
September 7, 2019 16:15
-
-
Save adamdriscoll/a1751599c8e55db3b54da1944fb00825 to your computer and use it in GitHub Desktop.
JavaScript Controller Asset Endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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