C
C#8mo ago
Alex

Serve SPA (React) in ASP.NET web API

Is it a correct way to serve SPA in ASP.NET Web API project? Is there a better way to do it? The way I do it is to move React built to wwwroot and add lines to useStaticFiles and MapFallbackToFile to index.html Program.cs
...

var app = builder.Build();

// Configure the HTTP request pipeline.

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

using (var scope = app.Services.CreateScope())
{
DbInitializer.Seed(scope).Wait();
}

app.UseHttpsRedirection();


app.UseExceptionHandler();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.UseDefaultFiles();
app.UseStaticFiles();
app.MapFallbackToFile("index.html");

app.Run();
...

var app = builder.Build();

// Configure the HTTP request pipeline.

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

using (var scope = app.Services.CreateScope())
{
DbInitializer.Seed(scope).Wait();
}

app.UseHttpsRedirection();


app.UseExceptionHandler();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();

app.UseDefaultFiles();
app.UseStaticFiles();
app.MapFallbackToFile("index.html");

app.Run();
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server