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
4 changes: 4 additions & 0 deletions docs/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ Once a release of .NET Aspire with that API is available, the API in the .NET As
## CTASPIRE002

Support for loading extensions into SQLite requires either a NuGet package or folder path to the library to be provided, and as a result there is some custom logic to load the extension based on the path or NuGet package. This logic will require some experimenting to figure out edge cases, so the feature for extension loading will be kept as experimental until it is proven to be stable.

## CTASPIRE003

The API is marked for deprecation and will be removed in a future release.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)"/>
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)" />

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -13,6 +13,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.csproj" IsAspireProjectResource="false" />
<ProjectReference Include="..\CommunityToolkit.Aspire.StaticWebApps.ApiApp\CommunityToolkit.Aspire.StaticWebApps.ApiApp.csproj" />
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps\CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.csproj" IsAspireProjectResource="false" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
.WithHttpHealthCheck("/health");

var web = builder
.AddNpmApp("web", Path.Combine(builder.AppHostDirectory, "..", "CommunityToolkit.Aspire.StaticWebApps.WebApp"), "dev")
.WithHttpEndpoint(env: "PORT")
.AddViteApp("web", Path.Combine(builder.AppHostDirectory, "..", "CommunityToolkit.Aspire.StaticWebApps.WebApp"))
.WithNpmPackageInstallation()
.WithHttpHealthCheck("/");

#pragma warning disable CTASPIRE003 // Type or member is obsolete
_ = builder
.AddSwaEmulator("swa")
.WithAppResource(web)
.WithApiResource(api);
#pragma warning restore CTASPIRE003 // Type or member is obsolete

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps library

**Deprecation warning**: This library is deprecated and will be removed in a future release, refer to https://github.com/CommunityToolkit/Aspire/issues/698 for more information.

Provides extensions methods and resource definitions for the .NET Aspire AppHost to support running Azure Static Web Apps locally using the emulator using the [Azure Static Web App CLI](https://learn.microsoft.com/azure/static-web-apps/local-development).

## Getting Started
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace Aspire.Hosting.ApplicationModel;
/// Represents an annotation for an API endpoint in a Static Web App.
/// </summary>
/// <param name="resource">The resource builder for resources with endpoints.</param>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public class SwaApiEndpointAnnotation(IResourceBuilder<IResourceWithEndpoints> resource) : IResourceAnnotation
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace Aspire.Hosting.ApplicationModel;
/// Initializes a new instance of the <see cref="SwaAppEndpointAnnotation"/> class.
/// </remarks>
/// <param name="resource">The resource builder for the endpoint.</param>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public class SwaAppEndpointAnnotation(IResourceBuilder<IResourceWithEndpoints> resource) : IResourceAnnotation
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace Aspire.Hosting;
/// <summary>
/// Provides extension methods for adding and configuring Static Web Apps emulator.
/// </summary>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public static class SwaAppHostingExtension
{
/// <summary>
Expand All @@ -14,6 +19,11 @@ public static class SwaAppHostingExtension
/// <param name="name">The name of the resource.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
/// <remarks>This resource will not be included in the published manifest.</remarks>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public static IResourceBuilder<SwaResource> AddSwaEmulator(this IDistributedApplicationBuilder builder, [ResourceName] string name) =>
builder.AddSwaEmulator(name, new SwaResourceOptions());

Expand All @@ -25,6 +35,11 @@ public static IResourceBuilder<SwaResource> AddSwaEmulator(this IDistributedAppl
/// <param name="options">The <see cref="SwaResourceOptions"/> to configure the SWA CLI.</param>"
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
/// <remarks>This resource will not be included in the published manifest.</remarks>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public static IResourceBuilder<SwaResource> AddSwaEmulator(this IDistributedApplicationBuilder builder, [ResourceName] string name, SwaResourceOptions options)
{
var resource = new SwaResource(name, Environment.CurrentDirectory);
Expand Down Expand Up @@ -62,6 +77,11 @@ public static IResourceBuilder<SwaResource> AddSwaEmulator(this IDistributedAppl
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> to add the resource to.</param>
/// <param name="appResource">The existing <see cref="IResourceBuilder{IResourceWithEndpoint}"/> to use as the <c>--app-devserver-url</c> argument.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public static IResourceBuilder<SwaResource> WithAppResource(this IResourceBuilder<SwaResource> builder, IResourceBuilder<IResourceWithEndpoints> appResource) =>
builder.WithAnnotation<SwaAppEndpointAnnotation>(new(appResource), ResourceAnnotationMutationBehavior.Replace).WaitFor(appResource);

Expand All @@ -71,6 +91,11 @@ public static IResourceBuilder<SwaResource> WithAppResource(this IResourceBuilde
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> to add the resource to.</param>
/// <param name="apiResource">The existing <see cref="IResourceBuilder{IResourceWithEndpoint}"/> to use as the <c>--api-devserver-url</c> argument.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public static IResourceBuilder<SwaResource> WithApiResource(this IResourceBuilder<SwaResource> builder, IResourceBuilder<IResourceWithEndpoints> apiResource) =>
builder.WithAnnotation<SwaApiEndpointAnnotation>(new(apiResource), ResourceAnnotationMutationBehavior.Replace).WaitFor(apiResource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Aspire.Hosting.ApplicationModel;
/// </remarks>
/// <param name="name">The name of the resource.</param>
/// <param name="workingDirectory">The working directory for the resource.</param>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public class SwaResource(string name, string workingDirectory) : ExecutableResource(name, "swa", workingDirectory)
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ namespace Aspire.Hosting;
/// <summary>
/// Represents the configuration options for a Static Web App resource.
/// </summary>
[Obsolete(
message: "The SWA emulator integration is going to be removed in a future release.",
error: false,
DiagnosticId = "CTASPIRE003",
UrlFormat = "https://github.com/CommunityToolit/aspire/issues/698")]
public class SwaResourceOptions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma warning disable CTASPIRE003
using Aspire.Hosting;

namespace CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
using CommunityToolkit.Aspire.Testing;
using System.Net.Http.Json;
//using CommunityToolkit.Aspire.Testing;
//using System.Net.Http.Json;

namespace CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests;
//namespace CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps.Tests;

public class SwaHostingComponentTests(AspireIntegrationTestFixture<Projects.CommunityToolkit_Aspire_StaticWebApps_AppHost> fixture) : IClassFixture<AspireIntegrationTestFixture<Projects.CommunityToolkit_Aspire_StaticWebApps_AppHost>>
{
[Fact]
public async Task CanAccessFrontendSuccessfully()
{
var httpClient = fixture.CreateHttpClient("swa");
//public class SwaHostingComponentTests(AspireIntegrationTestFixture<Projects.CommunityToolkit_Aspire_StaticWebApps_AppHost> fixture) : IClassFixture<AspireIntegrationTestFixture<Projects.CommunityToolkit_Aspire_StaticWebApps_AppHost>>
//{
// [Fact(Skip = "Test is unstable in CI")]
// public async Task CanAccessFrontendSuccessfully()
// {
// var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));

await fixture.ResourceNotificationService.WaitForResourceHealthyAsync("swa").WaitAsync(TimeSpan.FromMinutes(5));
// var httpClient = fixture.CreateHttpClient("swa");

var response = await httpClient.GetAsync("/");
// var ct = cts.Token;
// await fixture.ResourceNotificationService.WaitForResourceHealthyAsync("swa", ct);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
// var response = await httpClient.GetAsync("/", ct);

[Fact]
public async Task CanAccessApiSuccessfully()
{
var httpClient = fixture.CreateHttpClient("swa");
// Assert.Equal(HttpStatusCode.OK, response.StatusCode);
// }

await fixture.ResourceNotificationService.WaitForResourceHealthyAsync("swa").WaitAsync(TimeSpan.FromMinutes(5));
// [Fact(Skip = "Test is unstable in CI")]
// public async Task CanAccessApiSuccessfully()
// {
// var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
// var httpClient = fixture.CreateHttpClient("swa");

var response = await httpClient.GetAsync("/api/weather");
// var ct = cts.Token;
// await fixture.ResourceNotificationService.WaitForResourceHealthyAsync("swa", ct);

Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var forecasts = await response.Content.ReadFromJsonAsync<WeatherForecast[]>();
Assert.NotNull(forecasts);
Assert.Equal(6, forecasts.Length);
}
// var response = await httpClient.GetAsync("/api/weather", ct);

record WeatherForecast(DateTime Date, int TemperatureC, string Summary);
}
// Assert.Equal(HttpStatusCode.OK, response.StatusCode);
// var forecasts = await response.Content.ReadFromJsonAsync<WeatherForecast[]>(ct);
// Assert.NotNull(forecasts);
// Assert.Equal(6, forecasts.Length);
// }

// record WeatherForecast(DateTime Date, int TemperatureC, string Summary);
//}
Loading