question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to load API definition.

See original GitHub issue

Environments

  • Abp 3.8.1
  • ASP.NET CORE

I have download Abp asp.net core with Vue template after run project web.host, in browser navigate to http://localhost:12021, I get the error on he swagger page.

Fetch errorFailed to fetch http://localhost:21021/swagger/v1/swagger.json Fetch errorPossible cross-origin (CORS) issue? The URL origin (http://localhost:21021) does not match the page (http://localhost:12021). Check the server returns the correct 'Access-Control-Allow-*' headers.

I checked the Startup.cs get nothing about CROS exception code.

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        // MVC
        services.AddMvc(
            options => options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName))
        );

        IdentityRegistrar.Register(services);
        AuthConfigurer.Configure(services, _appConfiguration);

        services.AddSignalR();

        // Configure CORS for angular2 UI
        services.AddCors(
            options => options.AddPolicy(
                _defaultCorsPolicyName,
                builder => builder
                    .WithOrigins(
                        // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
                        _appConfiguration["App:CorsOrigins"]
                            .Split(",", StringSplitOptions.RemoveEmptyEntries)
                            .Select(o => o.RemovePostFix("/"))
                            .ToArray()
                    )
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials()
            )
        );

        // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
        services.AddSwaggerGen(options =>
        {
            options.SwaggerDoc("v1", new Info { Title = "Jifuwu API", Version = "v1" });
            options.DocInclusionPredicate((docName, description) => true);

            // Define the BearerAuth scheme that's in use
            options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
            {
                Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                Name = "Authorization",
                In = "header",
                Type = "apiKey"
            });
            // Assign scope requirements to operations based on AuthorizeAttribute
            options.OperationFilter<SecurityRequirementsOperationFilter>();
        });

        // Configure Abp and Dependency Injection
        return services.AddAbp<JifuwuWebHostModule>(
            // Configure Log4Net logging
            options => options.IocManager.IocContainer.AddFacility<LoggingFacility>(
                f => f.UseAbpLog4Net().WithConfig("log4net.config")
            )
        );
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseAbp(options => { options.UseAbpRequestLocalization = false; }); // Initializes ABP framework.

        app.UseCors(_defaultCorsPolicyName); // Enable CORS!

        app.UseStaticFiles();

        app.UseAuthentication();

        app.UseAbpRequestLocalization();


        app.UseSignalR(routes =>
        {
            routes.MapHub<AbpCommonHub>("/signalr");
        });

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "defaultWithArea",
                template: "{area}/{controller=Home}/{action=Index}/{id?}");

            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        // Enable middleware to serve generated Swagger as a JSON endpoint
        app.UseSwagger();
        // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
        app.UseSwaggerUI(options =>
        {
            options.SwaggerEndpoint(_appConfiguration["App:ServerRootAddress"] + "/swagger/v1/swagger.json", "Jifuwu API V1");
            options.IndexStream = () => Assembly.GetExecutingAssembly()
                .GetManifestResourceStream("Jifuwu.Web.Host.wwwroot.swagger.ui.index.html");
        }); // URL: /swagger
    }`

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ismcagdascommented, Aug 27, 2018

@tairan I think I understand the problem. If you look at the error details there are two different urls; http://localhost:21021 http://localhost:12021

Probably this will fix your problem https://github.com/aspnetboilerplate/module-zero-core-template/pull/323

0reactions
tairancommented, Aug 27, 2018

Yes, @ismcagdas you are right. it is fixed. thank you very much. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swashbuckle/Swagger + ASP.Net Core: "Failed to load API ...
As soon as I explicitly set e.g. [HttpGet] the error disappears. The problem with this is, I need this method to fire for...
Read more >
WebApi Core / Swagger: "failed to load API definition" error
I was working with some ASP.NET WebApi code and needed to test something using the Swagger UI. Usually, it's just a matter of...
Read more >
How To Solve Failed to load API definition Response ...
This error occurs when the API definition file fails to load due to an internal server error. In this article, we will discuss...
Read more >
Failed to load Swagger API definition for a Newly ...
I just pushed a .NET Core 6.0 WebAPI to Azure AppService. When I access the location I receive the following error issued when...
Read more >
Swagger Failed to load API definition In ASP.NET Core API
The solution is that you have to change the default route configuration at the controller level when you have created more than one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found