I'm having asp.net core with React project. It's web API along with a spa application project. From the spa, I want to be able to serve static files located in the wwwroot folder or from another folder called content from the client app. Here's my Startup.cs configuration
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseCors();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Content")),
RequestPath = new PathString("/Content")
});
app.UseSpaStaticFiles();
app.UseAuthentication();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
But Whenever I try to serve any file from both directories like https://domain/url_to_file, it gives me 404 file not found.
Any Idea about what I'm doing wrong here?
enter image description here