Skip to content

Commit 49579bc

Browse files
committed
web app fixes
1 parent 8708708 commit 49579bc

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

AstroAppHTTPAPI/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
// [MANDATORY] The assembly versioning
88
//Should be incremented for each new release build of a plugin
9-
[assembly: AssemblyVersion("1.0.1.3")]
10-
[assembly: AssemblyFileVersion("1.0.1.3")]
9+
[assembly: AssemblyVersion("1.0.1.4")]
10+
[assembly: AssemblyFileVersion("1.0.1.4")]
1111

1212
// [MANDATORY] The name of your plugin
1313
[assembly: AssemblyTitle("Astro HTTP API")]

AstroAppHTTPAPI/Web/WebServerManager.cs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
using Plugin.NINA.AstroAppHTTPAPI.Equipment;
77
using System;
88
using System.Linq;
9-
using System.Threading;
10-
using System.Timers;
119
using System.Net.NetworkInformation;
1210
using System.Security.Cryptography.X509Certificates;
13-
using System.Configuration;
14-
using EmbedIO.Files;
1511
using System.Text;
12+
using System.Threading;
13+
using System.Timers;
1614

1715
namespace Plugin.NINA.AstroAppHTTPAPI.Web {
1816

@@ -29,7 +27,7 @@ public class WebServerManager {
2927
private string certificatePath;
3028
private string certificatePassword;
3129

32-
public WebServerManager(int port, bool useHttps, string apiKey, EquipmentManager equipmentManager,
30+
public WebServerManager(int port, bool useHttps, string apiKey, EquipmentManager equipmentManager,
3331
string certificatePath, string certificatePassword) {
3432
this.port = port;
3533
this.equipmentManager = equipmentManager;
@@ -41,9 +39,9 @@ public WebServerManager(int port, bool useHttps, string apiKey, EquipmentManager
4139

4240
private void CreateServer() {
4341
webSocketHandler = new WebSocketHandler("/events/v1", equipmentManager, apiKey);
44-
42+
4543
var urlPrefix = useHttps ? $"https://*:{port}" : $"http://*:{port}";
46-
44+
4745
var options = new WebServerOptions()
4846
.WithUrlPrefix(urlPrefix)
4947
.WithMode(HttpListenerMode.EmbedIO);
@@ -64,10 +62,6 @@ private void CreateServer() {
6462
.WithModule(new CorsModule("/", "*", "*", "*"))
6563
.WithModule(webSocketHandler)
6664
.WithModule(new BasicAuthenticationModule("/api").WithAccount("user", apiKey))
67-
.WithAction("/", HttpVerbs.Get, ctx => {
68-
ctx.Response.ContentType = "text/html";
69-
return ctx.SendStringAsync(StaticContent.GetIndexHtml(), "text/html", Encoding.UTF8);
70-
})
7165
.WithWebApi("/api/v1/camera", m => m.WithController(() => new CameraRouteController(null, equipmentManager)))
7266
.WithWebApi("/api/v1/dome", m => m.WithController(() => new DomeRouteController(null, equipmentManager)))
7367
.WithWebApi("/api/v1/mount", m => m.WithController(() => new MountRouteController(null, equipmentManager)))
@@ -77,8 +71,11 @@ private void CreateServer() {
7771
.WithWebApi("/api/v1/filterwheel", m => m.WithController(() => new FilterWheelRouteController(null, equipmentManager)))
7872
.WithWebApi("/api/v1/flatdevice", m => m.WithController(() => new FlatDeviceRouteController(null, equipmentManager)))
7973
.WithWebApi("/api/v1/safetymonitor", m => m.WithController(() => new SafetyMonitorController(null, equipmentManager)))
80-
.WithWebApi("/api/v1/weather", m => m.WithController(() => new WeatherRouteController(null, equipmentManager)));
81-
74+
.WithWebApi("/api/v1/weather", m => m.WithController(() => new WeatherRouteController(null, equipmentManager)))
75+
.WithAction("/", HttpVerbs.Any, ctx => {
76+
ctx.Response.ContentType = "text/html";
77+
return ctx.SendStringAsync(StaticContent.GetIndexHtml(), "text/html", Encoding.UTF8);
78+
});
8279
UpdateServerUrls();
8380
}
8481

@@ -91,9 +88,9 @@ private void UpdateServerUrls() {
9188
.Where(x => x.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
9289
.Select(x => $"{protocol}://{x.Address}:{port}")
9390
.ToList();
94-
91+
9592
ServerUrls = string.Join("\n", addresses);
96-
93+
9794
// Add localhost if not already included
9895
if (!addresses.Any(x => x.Contains("127.0.0.1"))) {
9996
ServerUrls = $"{protocol}://127.0.0.1:{port}\n" + ServerUrls;
@@ -172,19 +169,17 @@ public string ApiKey {
172169

173170
}
174171

175-
private X509Certificate2 GetCertificate()
176-
{
172+
private X509Certificate2 GetCertificate() {
177173
try {
178174
if (string.IsNullOrEmpty(certificatePath)) {
179175
throw new Exception("No certificate path specified");
180176
}
181177

182178
return new X509Certificate2(
183-
certificatePath,
179+
certificatePath,
184180
certificatePassword ?? ""
185181
);
186-
}
187-
catch (Exception ex) {
182+
} catch (Exception ex) {
188183
throw new Exception($"Failed to load certificate: {ex.Message}");
189184
}
190185
}

0 commit comments

Comments
 (0)