Skip to content

Commit

Permalink
Sample for SWA emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Aug 20, 2024
1 parent 7d7d34d commit c07d088
Show file tree
Hide file tree
Showing 29 changed files with 4,004 additions and 7 deletions.
11 changes: 9 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"installGradle": true,
"installMaven": true
},
"ghcr.io/devcontainers/features/docker-in-docker": {}
"ghcr.io/devcontainers/features/docker-in-docker": {},
"ghcr.io/devcontainers/features/node:latest": {}
},

"customizations": {
Expand All @@ -40,6 +41,12 @@

"hostRequirements": {
"memory": "8gb"
},

"portsAttributes": {
"4280": {
"label": "SWA Emulator",
"onAutoForward": "notify"
}
}
}

2 changes: 2 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ dotnet linux-dev-certs install

## Install Spring Boot CLI
# sdk install springboot

npm install -g @azure/static-web-apps-cli
34 changes: 29 additions & 5 deletions CommunityToolkit.Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hos
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Testing", "tests\CommunityToolkit.Aspire.Testing\CommunityToolkit.Aspire.Testing.csproj", "{4C1D5422-4C52-4603-A01A-E1E6304633EC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "swa", "swa", "{564FA6A0-EC54-41C6-A35F-89890E1D06E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.StaticWebApps.AppHost", "examples\swa\CommunityToolkit.Aspire.StaticWebApps.AppHost\CommunityToolkit.Aspire.StaticWebApps.AppHost.csproj", "{C083A377-13CA-47C1-8B17-1FE353EA76F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.StaticWebApps.ApiApp", "examples\swa\CommunityToolkit.Aspire.StaticWebApps.ApiApp\CommunityToolkit.Aspire.StaticWebApps.ApiApp.csproj", "{BAEA0F6F-39E9-4893-8787-C4D292D3B169}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.StaticWebApps.ServiceDefaults", "examples\swa\CommunityToolkit.Aspire.StaticWebApps.ServiceDefaults\CommunityToolkit.Aspire.StaticWebApps.ServiceDefaults.csproj", "{83FF8083-7EE2-4196-86A8-239F921B443C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +47,10 @@ Global
{DAA67050-44B3-458F-9818-5877D606866A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAA67050-44B3-458F-9818-5877D606866A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAA67050-44B3-458F-9818-5877D606866A}.Release|Any CPU.Build.0 = Release|Any CPU
{125DFA83-328D-4F8B-91EC-3057FFF410BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{125DFA83-328D-4F8B-91EC-3057FFF410BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{125DFA83-328D-4F8B-91EC-3057FFF410BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{125DFA83-328D-4F8B-91EC-3057FFF410BE}.Release|Any CPU.Build.0 = Release|Any CPU
{3D767C8C-7E04-4264-B4E9-13600650D2B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D767C8C-7E04-4264-B4E9-13600650D2B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D767C8C-7E04-4264-B4E9-13600650D2B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -59,10 +71,6 @@ Global
{E2905A71-E25D-46FC-A128-D6A366D4D751}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2905A71-E25D-46FC-A128-D6A366D4D751}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2905A71-E25D-46FC-A128-D6A366D4D751}.Release|Any CPU.Build.0 = Release|Any CPU
{125DFA83-328D-4F8B-91EC-3057FFF410BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{125DFA83-328D-4F8B-91EC-3057FFF410BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{125DFA83-328D-4F8B-91EC-3057FFF410BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{125DFA83-328D-4F8B-91EC-3057FFF410BE}.Release|Any CPU.Build.0 = Release|Any CPU
{1B55E682-B518-4E59-8972-07C82ED5A677}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B55E682-B518-4E59-8972-07C82ED5A677}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B55E682-B518-4E59-8972-07C82ED5A677}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -71,21 +79,37 @@ Global
{4C1D5422-4C52-4603-A01A-E1E6304633EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C1D5422-4C52-4603-A01A-E1E6304633EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C1D5422-4C52-4603-A01A-E1E6304633EC}.Release|Any CPU.Build.0 = Release|Any CPU
{C083A377-13CA-47C1-8B17-1FE353EA76F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C083A377-13CA-47C1-8B17-1FE353EA76F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C083A377-13CA-47C1-8B17-1FE353EA76F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C083A377-13CA-47C1-8B17-1FE353EA76F0}.Release|Any CPU.Build.0 = Release|Any CPU
{BAEA0F6F-39E9-4893-8787-C4D292D3B169}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAEA0F6F-39E9-4893-8787-C4D292D3B169}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAEA0F6F-39E9-4893-8787-C4D292D3B169}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAEA0F6F-39E9-4893-8787-C4D292D3B169}.Release|Any CPU.Build.0 = Release|Any CPU
{83FF8083-7EE2-4196-86A8-239F921B443C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83FF8083-7EE2-4196-86A8-239F921B443C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83FF8083-7EE2-4196-86A8-239F921B443C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83FF8083-7EE2-4196-86A8-239F921B443C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DAA67050-44B3-458F-9818-5877D606866A} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
{125DFA83-328D-4F8B-91EC-3057FFF410BE} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
{F120E99A-FB2A-4C3B-B588-9B7ED1CD4E8A} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
{3D767C8C-7E04-4264-B4E9-13600650D2B1} = {F120E99A-FB2A-4C3B-B588-9B7ED1CD4E8A}
{34602A2D-24B2-47C0-9678-F1F7CD6C8C6D} = {F120E99A-FB2A-4C3B-B588-9B7ED1CD4E8A}
{55AC8E7E-DA0A-489D-8059-4E7190C9EEBF} = {F120E99A-FB2A-4C3B-B588-9B7ED1CD4E8A}
{BBAFA814-1026-4A39-AA28-BCAE3951A224} = {F120E99A-FB2A-4C3B-B588-9B7ED1CD4E8A}
{E2905A71-E25D-46FC-A128-D6A366D4D751} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
{125DFA83-328D-4F8B-91EC-3057FFF410BE} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
{1B55E682-B518-4E59-8972-07C82ED5A677} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
{4C1D5422-4C52-4603-A01A-E1E6304633EC} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
{564FA6A0-EC54-41C6-A35F-89890E1D06E3} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
{C083A377-13CA-47C1-8B17-1FE353EA76F0} = {564FA6A0-EC54-41C6-A35F-89890E1D06E3}
{BAEA0F6F-39E9-4893-8787-C4D292D3B169} = {564FA6A0-EC54-41C6-A35F-89890E1D06E3}
{83FF8083-7EE2-4196-86A8-239F921B443C} = {564FA6A0-EC54-41C6-A35F-89890E1D06E3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08B1D4B8-D2C5-4A64-BB8B-E1A2B29525F0}
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<!-- Aspire packages -->
<PackageVersion Include="Aspire.Hosting" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.NodeJS" Version="$(AspireVersion)" />
<!-- AspNetCore packages -->
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.6.2" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Aspire.StaticWebApps.ServiceDefaults\CommunityToolkit.Aspire.StaticWebApps.ServiceDefaults.csproj" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

var app = builder.Build();

string[] summaries =
[
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
];

app.MapGet("/api/weather", () => Enumerable.Range(0, 6).Select(index => new WeatherForecast(
DateTime.Now.AddDays(index),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
)));

app.MapDefaultEndpoints();

app.Run();

record WeatherForecast(DateTime Date, int TemperatureC, string Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:28727",
"sslPort": 44394
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5297",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7019;http://localhost:5297",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>217620e8-b99b-48de-a85a-cb33d49baa25</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.NodeJS" />
</ItemGroup>

<ItemGroup>
<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>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps;

var builder = DistributedApplication.CreateBuilder(args);

var api = builder.AddProject<Projects.CommunityToolkit_Aspire_StaticWebApps_ApiApp>("api");

var web = builder
.AddNpmApp("web", Path.Combine("..", "CommunityToolkit.Aspire.StaticWebApps.WebApp"), "dev")
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints();

_ = builder
.AddSwaEmulator("swa")
.WithAppResource(web)
.WithApiResource(api);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17178;http://localhost:15062",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21053",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22295"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15062",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19191",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20099"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<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>
Loading

0 comments on commit c07d088

Please sign in to comment.