How to add SwaggerUI to "ASP.NET Core with React.js" project

Viewed 44

I created ASP.NET Core with React.js project

enter image description here

I installed NuGet package Swashbuckle.AspNetCore

Updated Program.cs

...
builder.Services.AddSwaggerGen();
var app = builder.Build();
...
app.UseRouting();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller}/{action=Index}/{id?}");

app.MapFallbackToFile("index.html");

app.UseSwagger();
app.UseSwaggerUI();
            
app.Run();

But I am not able to display the Swagger UI webpage, because it seems that the URL is handled in the JavaScript.

How should I update the routing?

1 Answers

I found the answer here https://stackoverflow.com/a/73091128/2333663 it's necessary to update following file and register swagger endpoint

ClientApp/src/setupProxy.js

const context =  [
  "/swagger"
  "/weatherforecast",
];
Related