builder.Configure() stops API explorer loading

If I add this to a modular startup:

        builder.Configure(app =>
        {
             //empty
        });

Then I get a 404 when I visit localhost:port/ui to look at the api explorer.

I found this because I added Hangfire dashboard like so:

        builder.Configure(app =>
        {
            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                Authorization = new[] { new HangFireAuthorizationFilter() }
            });
        });

Then noticed the api explorer didn’t load even when I commented the inner code out.

I am using ServiceStack 6.9.0.

Any ideas what I can do to have both working together?

Sounds like the request is being handled before it’s able to reach ServiceStack. Is your app.UseServiceStack(new AppHost()) registered at the start of the pipeline?

In my program.cs I have:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
    app.UseHttpsRedirection();
}

app.UseServiceStack(new AppHost());

app.Run();

but if I add in:

[assembly: HostingStartup(typeof(ConfigureHangfire))]
namespace Project.Configure;
public class ConfigureHangfire : IHostingStartup
{
    public void Configure(IWebHostBuilder builder)
    {

        builder.Configure(app =>
        {

        });

    }
}

Then all the ServiceStack routes like /ui and /metadata stop working. I tried making a branch with ServiceStack 8 to see if any difference but it’s the same behaviour.

The IHostingStartup classes are run before Program.cs so it might be hijacking the request, preventing it from reaching ServiceStack. Does it work when you configure Hangfire after ServiceStack?

app.UseServiceStack(new AppHost());
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
    Authorization = new[] { new HangFireAuthorizationFilter() }
});

Aha Success!

Moving it to Program.cs worked. Thanks, as always amazing support!

1 Like