Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 88 additions & 6 deletions src/App.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,88 @@
<Router AppAssembly="@typeof(App).Assembly" NotFoundPage="typeof(Pages.NotFound)">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
</Router>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Synentra Console</title>
<base href="/" />
<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.min.css" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/app.css" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<link href="Console.styles.css" rel="stylesheet" />
<script>
(function () {
var themeClass = "app-theme-light";

try {
var preferenceJson = window.localStorage.getItem("ConsolePreference");

if (preferenceJson) {
var preference = JSON.parse(preferenceJson);
if (preference && preference.IsDarkMode === true) {
themeClass = "app-theme-dark";
}
}
} catch {
}

document.documentElement.classList.add(themeClass);
})();

window.synentraLoader = window.synentraLoader || {
dismiss: function () {
var splash = document.getElementById("app-splash");
if (!splash) {
return;
}

splash.classList.add("app-loading-hidden");

window.setTimeout(function () {
splash.remove();
}, 260);
}
};
</script>
<HeadOutlet @rendermode="InteractiveServer" />
<script type="importmap"></script>
</head>

<body>
<div id="app-splash" class="app-loading">
<div class="loading-brand">
<div class="loading-logo">
<img src="logo.png"
alt="Synentra"
class="loading-logo-image" />
</div>

<div class="loading-wordmark">
SYNENTRA
</div>
</div>

<div class="loading-spinner" aria-label="Loading">
<div class="loading-spinner-ring"></div>
<div class="loading-spinner-dot"></div>
</div>

<div class="loading-status">
<span class="loading-status-dot"></span>
Initializing Console
</div>
</div>

<Routes @rendermode="InteractiveServer" />

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="." class="reload">Reload</a>
<span class="dismiss">🗙</span>
</div>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script src="_framework/blazor.web.js"></script>
</body>

</html>
2 changes: 0 additions & 2 deletions src/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.11" PrivateAssets="all" />
<PackageReference Include="MudBlazor" Version="8.6.0" />
</ItemGroup>

Expand Down
18 changes: 18 additions & 0 deletions src/Extensions/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Console.Settings;

namespace Console.Extensions;

public static class ApplicationBuilderExtensions
{
public static IApplicationBuilder UseHttps(this IApplicationBuilder app)
{
var serviceProvider = app.ApplicationServices;
var endpointConfiguration = serviceProvider.GetService<EndpointConfiguration>();
if (endpointConfiguration != null && endpointConfiguration.Https?.Enabled == true)
{
app.UseHttpsRedirection();
}

return app;
}
}
45 changes: 45 additions & 0 deletions src/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Blazored.LocalStorage;
using Console.Preferences;
using Console.Services;
using Console.Settings;
using MudBlazor;
using MudBlazor.Services;

namespace Console.Extensions;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddConsoleServices(this IServiceCollection services)
{
services.AddServerSideBlazor();
services
.AddBlazoredLocalStorage()
.AddScoped<IPreferenceManager, PreferenceManager>()
.AddScoped<ConsoleState>()
.AddScoped<SynentraApiClient>()
.AddHttpClient()
.AddHttpContextAccessor();

return services;
}

public static IServiceCollection AddMudBlazor(this IServiceCollection services) =>
services.AddMudServices(ConfigureMudSnackbar);

#region Private Helpers

private static void ConfigureMudSnackbar(MudServicesConfiguration config)
{
var snackbar = config.SnackbarConfiguration;
snackbar.PositionClass = Defaults.Classes.Position.BottomRight;
snackbar.HideTransitionDuration = 500;
snackbar.ShowTransitionDuration = 500;
snackbar.VisibleStateDuration = 10000;
snackbar.PreventDuplicates = false;
snackbar.NewestOnTop = false;
snackbar.ShowCloseIcon = true;
snackbar.SnackbarVariant = Variant.Filled;
}

#endregion
}
82 changes: 82 additions & 0 deletions src/Extensions/WebApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Console.Settings;

namespace Console.Extensions;

public static class WebApplicationBuilderExtensions
{
public static WebApplicationBuilder ConfigureHttpServer(this WebApplicationBuilder builder)
{
var endpointConfiguration = new EndpointConfiguration();
builder.Configuration.GetSection("Endpoints").Bind(endpointConfiguration);
builder.Services.AddSingleton(endpointConfiguration);

using var scope = builder.Services.BuildServiceProvider().CreateScope();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();

ConfigureKestrelEndpoints(builder, endpointConfiguration, logger);
ConfigureKestrelSettings(builder);

return builder;
}

private static void ConfigureKestrelEndpoints(
WebApplicationBuilder builder,
EndpointConfiguration config,
ILogger logger)
{
builder.WebHost.ConfigureKestrel((_, options) =>
{
var httpPort = config.Http?.Port ?? 8180;
int? httpsPort = null;

if (config.Https?.Enabled == true)
{
httpsPort = config.Https.Port ?? 8443;

if (httpsPort == httpPort)
throw new InvalidOperationException($"HTTP and HTTPS endpoint ports cannot be the same: {httpPort}");
}

options.ListenAnyIP(httpPort);

if (httpsPort.HasValue)
{
options.ListenAnyIP(httpsPort.Value, listenOptions =>
{
var cert = config.Https!.Certificate;

if (cert != null)
{
if (!string.IsNullOrWhiteSpace(cert.Password))
{
listenOptions.UseHttps(cert.Path, cert.Password);
}
else
{
listenOptions.UseHttps(cert.Path);
}
}
else
{
listenOptions.UseHttps();
}
});

logger.LogInformation("Configuring HTTP and HTTPS endpoints: HTTP {HttpPort}, HTTPS {HttpsPort}", httpPort, httpsPort);
}
else
{
logger.LogInformation("Configuring HTTP endpoint only: HTTP {HttpPort}", httpPort);
}
});
}

private static void ConfigureKestrelSettings(WebApplicationBuilder builder)
{
builder.WebHost.UseKestrel(options =>
{
options.AddServerHeader = false;
options.Limits.MaxRequestBufferSize = null;
});
}
}
1 change: 1 addition & 0 deletions src/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
_isDarkMode = await PreferenceManager.IsDarkTheme();
_drawerOpen = await PreferenceManager.IsDrawerOpenAsync();
_initialized = true;
await JS.InvokeVoidAsync("synentraLoader.dismiss");
StateHasChanged();
}
}
Expand Down
38 changes: 9 additions & 29 deletions src/wwwroot/index.html → src/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
@page "/"
@namespace Console.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.AspNetCore.Components.Web

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Synentra Console</title>
<base href="/" />
<link rel="preload" id="webassembly" />
<base href="~/" />
<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.min.css" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/app.css" />
Expand All @@ -31,43 +35,19 @@
document.documentElement.classList.add(themeClass);
})();
</script>
<script type="importmap"></script>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>

<body>
<div id="app">
<div class="app-loading">
<div class="loading-brand">
<div class="loading-logo">
<img src="logo.png"
alt="Synentra"
class="loading-logo-image" />
</div>

<div class="loading-wordmark">
SYNENTRA
</div>
</div>

<div class="loading-spinner" aria-label="Loading">
<div class="loading-spinner-ring"></div>
<div class="loading-spinner-dot"></div>
</div>

<div class="loading-status">
<span class="loading-status-dot"></span>
Initializing Console
</div>
</div>
</div>
<component type="typeof(App)" render-mode="ServerPrerendered" />

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="." class="reload">Reload</a>
<span class="dismiss">🗙</span>
</div>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_framework/blazor.server.js"></script>
</body>

</html>
Loading
Loading