Friday, July 27, 2018

ASP .NET CORE with Angular 6 Template and Swagger

This may be one of those forehead-slapping obvious things that should never have slowed me down so much. I wanted to add Swagger usage to my new .Net Core Angular application, and kept getting issues with the Swagger user interface being the start and default page of the site. Of course, if you use Swagger, you know you would prefer to only get to it by typing your site's url, with "/swagger" appended to the end. This way it sits quietly in the background as a developer/analyst tool.

Well, the Captain Obvious setting that works for me is, change the RoutePrefix from String.Empty to "swagger".

c.RoutePrefix = "swagger";

The site loads to the expected default page of the SPA and runs the route I specified for empty string, which is just the Index.html in the ClientApp folder. Only when I change the URL in the browser do I get to Swagger.

I read probably 10 websites about how to do this, and you can guess, none of them made it simple and most just confused the issue big time. People wrote up something called a "SPA fallback" configuration. I don't know what that is, and apparently, don't need to.