Skip to content

Commit

Permalink
chore: scaffold web project
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBabbitt97 committed Dec 28, 2024
1 parent 380aca9 commit acf7959
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.10.0" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions Rapture.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D2B8BBC7-DCE
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rapture.AppHost", "src\AppHost\Rapture.AppHost.csproj", "{611BC7D0-0DA2-46AC-843E-6D6FE8981FEB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rapture.Web", "src\Web\Rapture.Web.csproj", "{E1FDFA83-A5ED-4CFA-BEE1-913F7CA6106B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,11 +19,16 @@ Global
{611BC7D0-0DA2-46AC-843E-6D6FE8981FEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{611BC7D0-0DA2-46AC-843E-6D6FE8981FEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{611BC7D0-0DA2-46AC-843E-6D6FE8981FEB}.Release|Any CPU.Build.0 = Release|Any CPU
{E1FDFA83-A5ED-4CFA-BEE1-913F7CA6106B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1FDFA83-A5ED-4CFA-BEE1-913F7CA6106B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1FDFA83-A5ED-4CFA-BEE1-913F7CA6106B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1FDFA83-A5ED-4CFA-BEE1-913F7CA6106B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{611BC7D0-0DA2-46AC-843E-6D6FE8981FEB} = {D2B8BBC7-DCE7-4BA9-AEA1-59BD146B5A72}
{E1FDFA83-A5ED-4CFA-BEE1-913F7CA6106B} = {D2B8BBC7-DCE7-4BA9-AEA1-59BD146B5A72}
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions src/AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.Rapture_Web>("web")
.WithHttpEndpoint(name: "version", port: 54996);

builder.Build().Run();
4 changes: 4 additions & 0 deletions src/AppHost/Rapture.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<PackageReference Include="Aspire.Hosting.AppHost" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Web\Rapture.Web.csproj" />
</ItemGroup>

</Project>
119 changes: 119 additions & 0 deletions src/Web/Core/CoreExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Licensed to the Rapture Project under one or more agreements.
// The Rapture Project licenses this file to you under the MIT license.

using Azure.Monitor.OpenTelemetry.AspNetCore;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

namespace Rapture.Web.Core;

/// <summary>
/// Core extension methods.
/// </summary>
public static class CoreExtensions
{
/// <summary>
/// Adds core configuration to a <see cref="IHostApplicationBuilder"/>.
/// </summary>
/// <param name="builder">The <see cref="IHostApplicationBuilder"/> to add configuration to.</param>
/// <returns>The <see cref="IHostApplicationBuilder"/> to continue adding configuration to.</returns>
public static IHostApplicationBuilder ConfigureCore(this IHostApplicationBuilder builder)
{
builder.ConfigureTelemetry()
.ConfigureHealthChecks()
.ConfigureServiceDiscovery()
.ConfigureHttpClient();

return builder;
}

/// <summary>
/// Adds core middleware to a <see cref="WebApplication"/>.
/// </summary>
/// <param name="app">The <see cref="WebApplication"/> to add middleware to.</param>
/// <returns>The <see cref="WebApplication"/> to continue adding middleware to.</returns>
public static WebApplication UseCore(this WebApplication app)
{
app.UseHealthChecks();

return app;
}

private static IHostApplicationBuilder ConfigureTelemetry(this IHostApplicationBuilder builder)
{
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddRuntimeInstrumentation()
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation();
})
.WithTracing(tracing =>
{
tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation();
});

if (!string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]))
{
builder.Services.AddOpenTelemetry()
.UseOtlpExporter();
}

if (!string.IsNullOrWhiteSpace(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
{
builder.Services.AddOpenTelemetry()
.UseAzureMonitor();
}

return builder;
}

private static IHostApplicationBuilder ConfigureHealthChecks(this IHostApplicationBuilder builder)
{
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);

return builder;
}

private static WebApplication UseHealthChecks(this WebApplication app)
{
app.MapHealthChecks("/health");

app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});

return app;
}

private static IHostApplicationBuilder ConfigureServiceDiscovery(this IHostApplicationBuilder builder)
{
builder.Services.AddServiceDiscovery();

return builder;
}

private static IHostApplicationBuilder ConfigureHttpClient(this IHostApplicationBuilder builder)
{
builder.Services.ConfigureHttpClientDefaults(http =>
{
http.AddStandardResilienceHandler();
http.AddServiceDiscovery();
});

return builder;
}
}
14 changes: 14 additions & 0 deletions src/Web/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the Rapture Project under one or more agreements.
// The Rapture Project licenses this file to you under the MIT license.

using Rapture.Web.Core;

var builder = WebApplication.CreateBuilder(args);

builder.ConfigureCore();

var app = builder.Build();

app.UseCore();

app.Run();
12 changes: 12 additions & 0 deletions src/Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"Rapture.Web": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
18 changes: 18 additions & 0 deletions src/Web/Rapture.Web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions src/Web/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/Web/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit acf7959

Please sign in to comment.