0

I deployed a ASP.net core swagger API in Azure K8s cluster when im verifying it reaching the main page using curl -I localhost:5100 i got error 404 while when im trying curl -I locolhost:5100/index.html i got the respond 200.

what could be causing this problem knowing this my startup class

  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var healthCheckOptions = new HealthCheckOptions
            {
                ResponseWriter = WriteReadinessResponse
            };

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHealthChecks("/health/readiness", healthCheckOptions);
                endpoints.MapHealthChecks("/health/liveness", new HealthCheckOptions()
                {
                    Predicate = (_) => false
                });
            });

            // enable swagger support
            app.UseSwagger();

            app.UseSwaggerUI(c =>
           {
               c.RoutePrefix = string.Empty;//all request to route [/] are being forward to index.html somehow
               c.SwaggerEndpoint("/swagger/v1/swagger.json", "Demo API V1");
           });
        }

is there a way how to fix this ? I like to get respond 200 when I curl -I localhost:5100.

1 Answer 1

0

DefaultFilesOptions It will redirect for default, if the url route do not specifies the static file.

Inside your configure method, try:

        var defaultFileOptions = new DefaultFilesOptions();
    defaultFileOptions.DefaultFileNames.Clear();
    defaultFileOptions.DefaultFileNames.Add("index.html");

    app.UseDefaultFiles(defaultFileOptions);
Sign up to request clarification or add additional context in comments.

1 Comment

The default url when you run the app is : localhost:5100/swagger/index.html , i used c.RoutePrefix = string.Empty to route localhost:5100 to localhost:5100/index.html, however your solution doesnt solve the problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.