Skip to content

Commit

Permalink
Fixes #201
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Oct 2, 2019
1 parent f1df42c commit 55e2877
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/UniversalDashboard/Cmdlets/StartDashboardCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/UniversalDashboard/Cmdlets/StartRestApiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/UniversalDashboard/Server/AutoReloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
});
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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; }
}


Expand Down
4 changes: 2 additions & 2 deletions src/UniversalDashboard/Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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)))
Expand Down

0 comments on commit 55e2877

Please sign in to comment.