Skip to content

Commit

Permalink
feat: Response compression (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender authored Aug 22, 2024
1 parent 0e1e99d commit 8f4d728
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 39 deletions.
11 changes: 5 additions & 6 deletions Client/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<mat-toolbar class="noselect main-toolbar" color="default">
<div class="toolbar-content">
<div>
<h1 class="no-wrap">
<a href="https://github.com/facioquo/stock-charts/" target="_blank" rel="noopener">
<a href="https://github.com/facioquo/stock-charts" target="_blank" rel="noopener">
stock chart
</a>
</h1>
<h2>
demo of
<strong>
<a href="https://dotnet.stockindicators.dev/" target="_blank" rel="noopener">
Stock Indicators for .NET</a>
</strong>
<a href="https://dotnet.stockindicators.dev" target="_blank" rel="noopener">
<strong>Stock Indicators for .NET</strong>
</a>
</h2>
</div>
</mat-toolbar>
Expand Down
2 changes: 1 addition & 1 deletion Client/src/app/app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

width: 100%;
max-width: 1024px;
min-height: 100vh;
margin: 0;
margin-right: auto;
margin-left: auto;
Expand All @@ -17,7 +18,6 @@
top: -56px;
right: 8px;
height: 100%;
min-height: 100vh;

button {
opacity: 0.6;
Expand Down
7 changes: 3 additions & 4 deletions Client/src/app/chart/chart.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!-- loading -->
<div *ngIf="cs.loading">
<div style="margin-top:175px;text-align:center;font-family:Rubik,Roboto,Arial,sans-serif;font-size:12px;color:#E6C74CD9;opacity:0.75;">
<p><img src="../assets/candle-spinner.svg" alt="loading" height="50"></p>
<p>LOADING</p>
<div style="font-family:Rubik,Roboto,Arial,sans-serif;font-size:10px;text-align:center;">
<p style="margin:0;padding-top:175px;"><img src="../assets/candle-spinner.svg" alt="loading" height="30" style="opacity:0.5;"></p>
<p style="margin-top:5px;color:#777;">LOADING</p>
</div>

</div>

<!-- CHART (MAIN OVERLAY) -->
Expand Down
8 changes: 4 additions & 4 deletions Client/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
"@type": "Website",
"name": "Stock Indicators for .NET (demo)",
"description": "A stock chart to demonstrate the Stock Indicators for .NET NuGet package. Transform price quotes into trading insights.",
"url": "https://charts.stockindicators.dev/",
"url": "https://charts.stockindicators.dev",
"image": "https://charts.stockindicators.dev/assets/icons/android-chrome-256x256.png",
"author": {
"@type": "Organization",
"name": "Skender Co.",
"url": "https://skenderco.com",
"logo": "https://skenderco.com/assets/logo.svg"
"name": "FacioQuo",
"url": "https://facioquo.com",
"logo": "https://facioquo.com/assets/logo.svg"
}
}
</script>
Expand Down
6 changes: 3 additions & 3 deletions Client/src/styles/_base-elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ mat-dialog-content {
padding-top: 1rem !important;

box-shadow:
0 0 3px 0 rgba(0, 0, 0, 0.20),
0 0 5px 0 rgba(0, 0, 0, 0.14),
0 0 8px 0 rgba(0, 0, 0, 0.12);
0 0 3px 0 rgb(0 0 0 / 20%),
0 0 5px 0 rgb(0 0 0 / 14%),
0 0 8px 0 rgb(0 0 0 / 12%);
}

mat-dialog-actions {
Expand Down
9 changes: 0 additions & 9 deletions Client/src/styles/_themed-parts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
.main-toolbar,
.mat-toolbar-single-row {

display: flex;
justify-content: left;

max-width: $maxwidth;
margin-left: auto;
margin-right: auto;
Expand All @@ -29,12 +26,6 @@
background-color: transparent;
line-height: unset !important;

.toolbar-content {
display: flex;
flex-direction: column;
align-items: left;
}

h1 {
font-family: Rubik, Roboto, Arial, Helvetica, sans-serif;
font-size: 1.4em;
Expand Down
1 change: 1 addition & 0 deletions Server/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_code_quality_unused_parameters = all:suggestion

dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
Expand Down
47 changes: 35 additions & 12 deletions Server/WebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// STARTUP CONFIGURATION

using Microsoft.Net.Http.Headers;
using System.IO.Compression;
using Microsoft.AspNetCore.ResponseCompression;
using WebApi.Services;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

IServiceCollection services = builder.Services;
ConfigurationManager configuration = builder.Configuration;

// add framework services
// Add framework services
services.AddControllers();

// get CORS origins from appsettings
// Get CORS origins from appsettings
// reminder: production origins defined in cloud host settings » API » CORS
// so these are really only for localhost / development
IConfigurationSection corsOrigins = configuration.GetSection("CorsOrigins");
Expand All @@ -21,10 +22,10 @@

if (!string.IsNullOrEmpty(allowedOrigin))
{
origins.Add(item: allowedOrigin);
origins.Add(allowedOrigin);
}

// setup CORS for website
// Setup CORS for website
services.AddCors(options => {
options.AddPolicy("CorsPolicy",
cors => {
Expand All @@ -38,23 +39,45 @@

Console.WriteLine($"CORS Origin: {allowedOrigin}");

// register services
// Register services
services.AddHostedService<StartupService>();
services.AddTransient<QuoteService>();

// build application
// Add response compression services
services.AddResponseCompression(options => {
options.EnableForHttps = true;
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
});

// Configure compression options
services.Configure<BrotliCompressionProviderOptions>(options => {
options.Level = CompressionLevel.Fastest;
});

services.Configure<GzipCompressionProviderOptions>(options => {
options.Level = CompressionLevel.Fastest;
});

// Build application
WebApplication app = builder.Build();

// configure the HTTP request pipeline
_ = app.Environment.IsDevelopment()
? app.UseDeveloperExceptionPage()
: app.UseHsts();
// Configure the HTTP request pipeline
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseRouting();
app.UseCors("CorsPolicy");
app.UseResponseCaching();
app.UseResponseCompression();

// controller endpoints
// Controller endpoints
app.MapControllers();
app.Run();

0 comments on commit 8f4d728

Please sign in to comment.