You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
I'm looking for a way to utilize the Swagger UI provided by this package in the angular starter. I've looked at the answer proposed in #1119 (which in turn references #973) and it seems things have changed a bit, as I have no call to MapSpaFallbackRoute in my Startup class. I am having the same issue described in these issues, in which the request to /swagger gets proxied to the SPA and thus ends up at a 404 error. I've tried moving the bits that enable the middleware above the call that enables mvc, not sure what else to do. Thanks for any help! Here's my Startup.cs if it helps at all:
publicclassStartup{publicStartup(IConfigurationconfiguration){Configuration=configuration;}publicIConfigurationConfiguration{get;}// This method gets called by the runtime. Use this method to add services to the container.publicvoidConfigureServices(IServiceCollectionservices){services.AddDbContext<ApplicationDbContext>(options =>{options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"));});services.AddIdentity<ApplicationUser,ApplicationRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();services.AddAuthentication(opts =>{opts.DefaultAuthenticateScheme=JwtBearerDefaults.AuthenticationScheme;opts.DefaultChallengeScheme=JwtBearerDefaults.AuthenticationScheme;}).AddJwtBearer(options =>{options.TokenValidationParameters=newTokenValidationParameters{ValidateIssuer=true,ValidateAudience=true,ValidateLifetime=true,ClockSkew=TimeSpan.Zero,ValidateIssuerSigningKey=true,ValidIssuer=Configuration["Jwt:Issuer"],ValidAudience=Configuration["Jwt:Issuer"],IssuerSigningKey=newSymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))};});services.AddAuthorization(options =>{options.AddPolicy("TestPolicy", policy =>policy.RequireClaim("testClaim","potato"));});services.AddMvc().AddJsonOptions(options =>{options.SerializerSettings.ReferenceLoopHandling=ReferenceLoopHandling.Ignore;});services.AddCors();// Allow injection of configurationservices.AddSingleton(Configuration);services.AddTransient<IUserService,ConsilioUserService>();services.AddTransient<ITimeService,ConsilioTimeService>();services.AddTransient<IHttpContextAccessor,HttpContextAccessor>();// In production, the Angular files will be served from this directoryservices.AddSpaStaticFiles(configuration =>{configuration.RootPath="ClientApp/dist";});services.AddSwaggerGen(c =>c.SwaggerDoc("v1",newInfo{Title="My API",Version="v1"}));}// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv){if(env.IsDevelopment()){app.UseDeveloperExceptionPage();}else{app.UseExceptionHandler("/Home/Error");}app.UseStaticFiles();app.UseSpaStaticFiles();app.UseCors(builder =>builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());app.UseAuthentication();// Enable middleware to serve generated Swagger as a JSON endpoint.app.UseSwagger();// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.app.UseSwaggerUI(c =>{c.SwaggerEndpoint("api/swagger/v1/swagger.json","My API V1");});app.UseMvc(routes =>{routes.MapRoute(name:"default",template:"{controller}/{action=Index}/{id?}");});app.UseSpa(spa =>{spa.Options.SourcePath="ClientApp";if(env.IsDevelopment()){// spa.UseAngularCliServer(npmScript: "start");spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");}});}
The text was updated successfully, but these errors were encountered:
The SPA fallback routing is only used if none of the other middleware is handling the request (since your UseSpa middleware appears last). So if /swagger gets served by the SPA middleware, it must not be correctly wired up to the Swagger middleware. Please check Swagger docs for more info on how to set it up.
@ADefWebserver I don't know - if auth was interfering, I'm not sure how that would result in it ending up in the SPA middleware. Maybe you're right though!
I'm looking for a way to utilize the Swagger UI provided by this package in the angular starter. I've looked at the answer proposed in #1119 (which in turn references #973) and it seems things have changed a bit, as I have no call to
MapSpaFallbackRoute
in my Startup class. I am having the same issue described in these issues, in which the request to/swagger
gets proxied to the SPA and thus ends up at a 404 error. I've tried moving the bits that enable the middleware above the call that enables mvc, not sure what else to do. Thanks for any help! Here's myStartup.cs
if it helps at all:The text was updated successfully, but these errors were encountered: