Last active
December 15, 2019 18:42
-
-
Save jiimaho/d454c9f82eecbd309bd1c07443caa6aa to your computer and use it in GitHub Desktop.
Pseudocode example: relation between UseDefaultFiles, UseSpaStaticFiles and UseSpa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// ... | |
services.AddSpaStaticFiles(configuration => | |
{ | |
configuration.RootPath = "wwwroot"; | |
}); | |
// ... | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app) | |
{ | |
// ... | |
app.UseSwagger(); | |
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1"); }); | |
app.UseMiddleware<HostLoggingMiddleware>(); | |
app.UseMiddleware<ContentSecurityPolicyMiddleware>(); | |
// Re-write path only. / to /index.html | |
app.UseDefaultFiles(); | |
// Start serve files from wwwroot (Must be after UseDefaultFiles obviously.) | |
app.UseSpaStaticFiles(); | |
app.UseRouting(); | |
// Your normal routes | |
app.UseEndpoints( | |
endpoints => | |
{ | |
endpoints.MapDefaultControllerRoute(); | |
endpoints.MapHealthChecks("/hc"); | |
}); | |
// Placed after normal routes, at end of pipeline, | |
// i.e. if request path did not match static content | |
// nor other routes, fallback to SPA | |
app.UseSpa(spa => | |
{ | |
if (_environment.IsDevelopment()) | |
{ | |
spa.UseProxyToSpaDevelopmentServer("http://localhost:4000"); | |
} | |
}); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment