.NET Aspire Azure Static Web Apps emulator integration
Raksts
Includes:
Hosting integration not
Client integration
Piezīme
This integration is part of the .NET Aspire Community Toolkit and isn't officially supported by the .NET Aspire team.
In this article, you learn how to use the .NET Aspire Azure Static Web Apps emulator hosting integration to run Azure Static Web Apps locally using the emulator. The emulator provides support for proxying both the static frontend and the API backend using resources defined in the app host.
This integration requires the Azure Static Web Apps CLI to run, and only supports hosting the emulator for local development, not deploying to Azure Static Web Apps.
In the Program.cs file of your app host project, define the backend and frontend resources. Then, call the AddSwaEmulator method to create the emulator and pass the resources using the WithAppResource and WithApiResource methods.
C#
var builder = DistributedApplication.CreateBuilder(args);
// Define the API resourcevar api = builder.AddProject<Projects.Aspire_CommunityToolkit_StaticWebApps_ApiApp>("api");
// Define the frontend resourcevar web = builder
.AddNpmApp("web", Path.Combine("..", "CommunityToolkit.Aspire.StaticWebApps.WebApp"), "dev")
.WithHttpEndpoint(env: "PORT")
.WithExternalHttpEndpoints();
// Create a SWA emulator with the frontend and API resources
_ = builder
.AddSwaEmulator("swa")
.WithAppResource(web)
.WithApiResource(api);
builder.Build().Run();
The preceding code defines the API and frontend resources and creates an emulator with the resources. The emulator is then started using the Run method.
Šī satura avotu var atrast vietnē GitHub, kur varat arī izveidot un pārskatīt problēmas un atgādāšanas pieprasījumus. Lai iegūtu papildinformāciju, skatiet mūsu līdzstrādnieku rokasgrāmatu.
.NET Aspire atsauksmes
.NET Aspire ir atklātā pirmkoda projekts. Atlasiet saiti, lai sniegtu atsauksmes:
Pievienojieties meetup sērijai, lai kopā ar citiem izstrādātājiem un ekspertiem izveidotu mērogojamus AI risinājumus, kuru pamatā ir reālas lietošanas gadījumi.
In this module, you learn about cloud-native applications and how the .NET Aspire stack makes it easier to develop microservices and connect them with each other and with supporting services.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.