Skip to content

Commit

Permalink
Merge pull request #1657 from tgstation/ControlPanelDiagnosticLogging…
Browse files Browse the repository at this point in the history
… [TGSDeploy]

Control panel diagnostic logging
  • Loading branch information
Cyberboss authored Sep 30, 2023
2 parents 4542675 + 02cce07 commit 694a9f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Integration tests will ensure they match across the board -->
<Import Project="ControlPanelVersion.props" />
<PropertyGroup>
<TgsCoreVersion>5.16.0</TgsCoreVersion>
<TgsCoreVersion>5.16.1</TgsCoreVersion>
<TgsConfigVersion>4.7.1</TgsConfigVersion>
<TgsApiVersion>9.12.0</TgsApiVersion>
<TgsCommonLibraryVersion>6.0.1</TgsCommonLibraryVersion>
Expand Down
24 changes: 23 additions & 1 deletion src/Tgstation.Server.Host/Controllers/ControlPanelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
Expand Down Expand Up @@ -39,6 +40,11 @@ public class ControlPanelController : Controller
/// </summary>
readonly IWebHostEnvironment hostEnvironment;

/// <summary>
/// The <see cref="ILogger"/> for the <see cref="ControlPanelController"/>.
/// </summary>
readonly ILogger<ControlPanelController> logger;

/// <summary>
/// The <see cref="ControlPanelConfiguration"/> for the <see cref="ControlPanelController"/>.
/// </summary>
Expand All @@ -49,10 +55,15 @@ public class ControlPanelController : Controller
/// </summary>
/// <param name="hostEnvironment">The value of <see cref="hostEnvironment"/>.</param>
/// <param name="controlPanelConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="controlPanelConfiguration"/>.</param>
public ControlPanelController(IWebHostEnvironment hostEnvironment, IOptions<ControlPanelConfiguration> controlPanelConfigurationOptions)
/// <param name="logger">The value of <see cref="logger"/>.</param>
public ControlPanelController(
IWebHostEnvironment hostEnvironment,
IOptions<ControlPanelConfiguration> controlPanelConfigurationOptions,
ILogger<ControlPanelController> logger)
{
this.hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
controlPanelConfiguration = controlPanelConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(controlPanelConfigurationOptions));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

/// <summary>
Expand All @@ -64,9 +75,14 @@ public ControlPanelController(IWebHostEnvironment hostEnvironment, IOptions<Cont
public IActionResult GetChannelJson()
{
if (!controlPanelConfiguration.Enable)
{
logger.LogDebug("Not serving channel.json as control panel is disabled.");
return NotFound();
}

var controlPanelChannel = controlPanelConfiguration.Channel;
logger.LogTrace("Generating channel.json for channel \"{channel}\"...", controlPanelChannel);

if (controlPanelChannel == "local")
controlPanelChannel = ControlPanelRoute;
else if (String.IsNullOrWhiteSpace(controlPanelChannel))
Expand Down Expand Up @@ -112,14 +128,18 @@ public override Task OnActionExecutionAsync(ActionExecutingContext context, Acti
public IActionResult Get([FromRoute] string appRoute)
{
if (!controlPanelConfiguration.Enable)
{
logger.LogDebug("Not serving static files as control panel is disabled.");
return NotFound();
}

if (Request.Headers.ContainsKey(FetchChannelVaryHeader))
return GetChannelJson();

var fileInfo = hostEnvironment.WebRootFileProvider.GetFileInfo(appRoute);
if (fileInfo.Exists)
{
logger.LogTrace("Serving static file \"{filename}\"...", appRoute);
var contentTypeProvider = new FileExtensionContentTypeProvider();
if (!contentTypeProvider.TryGetContentType(fileInfo.Name, out var contentType))
contentType = MediaTypeNames.Application.Octet;
Expand All @@ -130,6 +150,8 @@ public IActionResult Get([FromRoute] string appRoute)

return File(appRoute, contentType);
}
else
logger.LogTrace("Requested static file \"{filename}\" does not exist! Redirecting to index...", appRoute);

return File("index.html", MediaTypeNames.Text.Html);
}
Expand Down

0 comments on commit 694a9f4

Please sign in to comment.