@@ -23,10 +23,12 @@ namespace App
2323 public class Startup
2424 {
2525 public IConfiguration Configuration { get ; }
26+ public IHostingEnvironment Environment { get ; }
2627
27- public Startup ( IConfiguration configuration )
28+ public Startup ( IConfiguration configuration , IHostingEnvironment environment )
2829 {
2930 Configuration = configuration ;
31+ Environment = environment ;
3032
3133 Log . Logger = new LoggerConfiguration ( )
3234 . Enrich . FromLogContext ( )
@@ -110,16 +112,19 @@ public void ConfigureServices(IServiceCollection services)
110112 . AddApplicationPart ( typeof ( Core . Api . AuthorsController ) . GetTypeInfo ( ) . Assembly ) . AddControllersAsServices ( )
111113 . SetCompatibilityVersion ( CompatibilityVersion . Version_2_1 ) ;
112114
113- services . AddSwaggerGen ( setupAction => {
114- setupAction . SwaggerDoc ( "spec" ,
115+ if ( Environment . IsDevelopment ( ) )
116+ {
117+ services . AddSwaggerGen ( setupAction => {
118+ setupAction . SwaggerDoc ( "spec" ,
115119 new Microsoft . OpenApi . Models . OpenApiInfo ( )
116120 {
117121 Title = "Blogifier API" ,
118122 Version = "1"
119123 } ) ;
120- setupAction . IncludeXmlComments ( Path . Combine ( AppContext . BaseDirectory , "CoreAPI.xml" ) ) ;
121- } ) ;
122-
124+ setupAction . IncludeXmlComments ( Path . Combine ( AppContext . BaseDirectory , "CoreAPI.xml" ) ) ;
125+ } ) ;
126+ }
127+
123128 services . AddSpaStaticFiles ( configuration =>
124129 {
125130 configuration . RootPath = "wwwroot/themes/_active" ;
@@ -136,30 +141,30 @@ public void ConfigureServices(IServiceCollection services)
136141 services . AddAppServices ( ) ;
137142 }
138143
139- public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
144+ public void Configure ( IApplicationBuilder app )
140145 {
141- if ( env . IsDevelopment ( ) )
146+ if ( Environment . IsDevelopment ( ) )
142147 {
143148 app . UseDeveloperExceptionPage ( ) ;
149+
150+ app . UseSwagger ( ) ;
151+ app . UseSwaggerUI ( setupAction =>
152+ {
153+ setupAction . SwaggerEndpoint (
154+ "/swagger/spec/swagger.json" ,
155+ "Blogifier API"
156+ ) ;
157+ } ) ;
144158 }
145159
146160 app . UseCookiePolicy ( ) ;
147161 app . UseAuthentication ( ) ;
148162 app . UseStaticFiles ( ) ;
149163 app . UseSpaStaticFiles ( ) ;
150- app . UseRequestLocalization ( ) ;
151-
152- app . UseSwagger ( ) ;
153- app . UseSwaggerUI ( setupAction =>
154- {
155- setupAction . SwaggerEndpoint (
156- "/swagger/spec/swagger.json" ,
157- "Blogifier API"
158- ) ;
159- } ) ;
164+ app . UseRequestLocalization ( ) ;
160165
161- AppSettings . WebRootPath = env . WebRootPath ;
162- AppSettings . ContentRootPath = env . ContentRootPath ;
166+ AppSettings . WebRootPath = Environment . WebRootPath ;
167+ AppSettings . ContentRootPath = Environment . ContentRootPath ;
163168
164169 app . UseMvc ( routes =>
165170 {
0 commit comments