diff --git a/src/UniversalDashboard/Cmdlets/StartDashboardCommand.cs b/src/UniversalDashboard/Cmdlets/StartDashboardCommand.cs index c59bdbd3..8eabd6ab 100644 --- a/src/UniversalDashboard/Cmdlets/StartDashboardCommand.cs +++ b/src/UniversalDashboard/Cmdlets/StartDashboardCommand.cs @@ -138,7 +138,7 @@ protected override void EndProcessing() WriteWarning("AutoReload does not work on the command line. You must save your file as a script."); } - var server = new Server(Name, base.MyInvocation.ScriptName, AutoReload, Host, Port); + var server = new Server(Name, base.MyInvocation.ScriptName, AutoReload, Host, Port, Certificate != null || CertificateFile != null); var options = new DashboardOptions(); options.Dashboard = Dashboard; diff --git a/src/UniversalDashboard/Cmdlets/StartRestApiCommand.cs b/src/UniversalDashboard/Cmdlets/StartRestApiCommand.cs index 135cc50c..2e894bbc 100644 --- a/src/UniversalDashboard/Cmdlets/StartRestApiCommand.cs +++ b/src/UniversalDashboard/Cmdlets/StartRestApiCommand.cs @@ -74,7 +74,7 @@ protected override void EndProcessing() } } - var server = new Server(Name, MyInvocation.ScriptName, AutoReload, Host, Port); + var server = new Server(Name, MyInvocation.ScriptName, AutoReload, Host, Port, Certificate != null || CertificateFile != null); var options = new DashboardOptions(); options.StaticEndpoints = Endpoint; diff --git a/src/UniversalDashboard/Server/AutoReloader.cs b/src/UniversalDashboard/Server/AutoReloader.cs index 74bd68c9..bb3e0e38 100644 --- a/src/UniversalDashboard/Server/AutoReloader.cs +++ b/src/UniversalDashboard/Server/AutoReloader.cs @@ -22,7 +22,7 @@ public AutoReloader(PSHost host) { _host = host; } - public void StartWatchingFile(string fileName, int port, string reloadKey) { + public void StartWatchingFile(string fileName, int port, string reloadKey, bool https) { var fileInfo = new FileInfo(fileName); var fileSystemWatcher = new FileSystemWatcher(fileInfo.DirectoryName); @@ -32,7 +32,8 @@ public void StartWatchingFile(string fileName, int port, string reloadKey) { _dashboards.Add(fileInfo.FullName, new DashboardInfo { FileSystemWatcher = fileSystemWatcher, Port = port, - ReloadKey = reloadKey + ReloadKey = reloadKey, + Https = https }); } @@ -61,7 +62,9 @@ public void OnFileChanged(object source, FileSystemEventArgs e) { { var dashboardInfo = _dashboards.First(m => m.Key.Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)).Value; - var reloadRequest = WebRequest.CreateHttp($"http://localhost:{dashboardInfo.Port}/api/internal/dashboard/reload"); + var scheme = dashboardInfo.Https ? "https" : "http"; + + var reloadRequest = WebRequest.CreateHttp($"{scheme}://localhost:{dashboardInfo.Port}/api/internal/dashboard/reload"); reloadRequest.Headers.Add("x-ud-reload-token", dashboardInfo.ReloadKey); reloadRequest.Method = "GET"; var response = reloadRequest.GetResponse(); @@ -104,6 +107,7 @@ public class DashboardInfo { public int Port {get;set;} public FileSystemWatcher FileSystemWatcher {get;set;} public string ReloadKey {get;set;} + public bool Https { get; set; } } diff --git a/src/UniversalDashboard/Server/Server.cs b/src/UniversalDashboard/Server/Server.cs index 5678d80b..a08d96b8 100644 --- a/src/UniversalDashboard/Server/Server.cs +++ b/src/UniversalDashboard/Server/Server.cs @@ -24,7 +24,7 @@ namespace UniversalDashboard { public class Server { - public Server(string name, string fileName, bool autoReload, PSHost host, int port) + public Server(string name, string fileName, bool autoReload, PSHost host, int port, bool https) { if (string.IsNullOrEmpty(name)) { @@ -46,7 +46,7 @@ public Server(string name, string fileName, bool autoReload, PSHost host, int po } if (autoReload) { - _reloader.StartWatchingFile(fileName, Port, _reloadKey); + _reloader.StartWatchingFile(fileName, Port, _reloadKey, https); } if (Servers.Any(m => m.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)))