|
1 | 1 | using System.Reflection; |
| 2 | +using System.Runtime.InteropServices; |
2 | 3 | using Certify.Client; |
3 | 4 | using Certify.Management; |
4 | 5 | using Certify.Models; |
5 | 6 | using Certify.Models.Reporting; |
| 7 | +using Certify.Server.Core; |
6 | 8 | using Certify.Server.Hub.Api.Middleware; |
7 | 9 | using Certify.Server.Hub.Api.Services; |
8 | 10 | using Certify.Server.Hub.Api.SignalR; |
|
21 | 23 | List<ActionStep> _systemStatusItems = []; |
22 | 24 | void AddSystemStatusItem(string systemStatusCategory, string systemStatusKey, string title, string description, bool hasError = false, bool hasWarning = false) => _systemStatusItems.Add(new ActionStep(systemStatusKey, systemStatusCategory, title, description, hasError, hasWarning)); |
23 | 25 |
|
| 26 | +var assembly = typeof(Certify.Server.Hub.Api.Startup).Assembly; |
| 27 | + |
| 28 | +// set working directory so that when we are started as a service we can find our config |
| 29 | +var cwd = Path.GetDirectoryName(assembly.Location); |
| 30 | +if (cwd != null) |
| 31 | +{ |
| 32 | + System.Diagnostics.Debug.WriteLine($"Using working directory {cwd}"); |
| 33 | + Directory.SetCurrentDirectory(cwd); |
| 34 | +} |
| 35 | +else |
| 36 | +{ |
| 37 | + System.Diagnostics.Debug.WriteLine($"Could not determine working directory"); |
| 38 | +} |
| 39 | + |
24 | 40 | var builder = WebApplication.CreateBuilder(args); |
25 | 41 |
|
| 42 | +// if windows, run as service, otherwise run as console app |
| 43 | +if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 44 | +{ |
| 45 | + builder.Services.AddWindowsService() |
| 46 | + .AddHostedService<WindowsBackgroundService>(); |
| 47 | +} |
| 48 | + |
26 | 49 | builder.AddServiceDefaults(); |
27 | 50 |
|
28 | 51 | AddSystemStatusItem( |
|
34 | 57 |
|
35 | 58 | // Add services to the container |
36 | 59 |
|
37 | | -var assembly = typeof(Certify.Server.Hub.Api.Startup).Assembly; |
38 | 60 | var part = new AssemblyPart(assembly); |
39 | 61 |
|
40 | 62 | builder.Services.AddCors(options => |
|
219 | 241 |
|
220 | 242 | app.MapDefaultControllerRoute().WithStaticAssets(); |
221 | 243 |
|
222 | | -// publish scalar api docs endpoint in dev, e.g. https://localhost:44361/scalar/ |
223 | | -app.MapOpenApi(); |
224 | | -app.MapScalarApiReference(); |
| 244 | +// publish scalar api docs endpoint in dev, e.g. https://localhost:44361/api/docs |
225 | 245 |
|
226 | 246 | // Enable middleware to serve generated Swagger as a JSON endpoint. |
227 | 247 | app.UseSwagger(); |
228 | 248 |
|
229 | | -// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), |
230 | | -// specifying the Swagger JSON endpoint. |
231 | | -app.UseSwaggerUI(c => |
| 249 | +// Enable middleware to serve API docs |
| 250 | +app.MapScalarApiReference("/api/docs/", options => |
232 | 251 | { |
233 | | - c.RoutePrefix = "docs"; |
234 | | - c.DocumentTitle = "Certify Management Hub API"; |
235 | | - c.SwaggerEndpoint("/swagger/v1/swagger.json", "Certify Management Hub API"); |
| 252 | + options |
| 253 | + .WithTitle("Certify Management Hub API") |
| 254 | + .WithTheme(ScalarTheme.Solarized) |
| 255 | + .WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient) |
| 256 | + .WithOpenApiRoutePattern("/swagger/v1/swagger.json"); |
| 257 | + |
236 | 258 | }); |
237 | 259 |
|
238 | 260 | AddSystemStatusItem( |
239 | 261 | SystemStatusCategories.HUB_API, |
240 | 262 | SystemStatusKeys.HUB_API_STARTUP_SWAGGER, |
241 | 263 | title: "API Docs UI enabled", |
242 | | - description: $"Hub API Swagger docs available at /docs" |
| 264 | + description: $"Hub API docs available at /api/docs" |
243 | 265 | ); |
244 | 266 |
|
245 | 267 | // configure initialization of UI status hub, backend management hub etc |
|
0 commit comments