Avatar

Is AI any good at programming?

Published: May 3, 2025 - Updated: May 23, 2025

So I thought I'd give this vibe-coding a go and you know what, it's not without it's flaws.

My original prompt was:-

Using jet brains rider i want a cSharp .net 8 project for a web app that has a controller based API back-end and will serve a static HTML site for any request that is not part of the API routing.

After a few hours of back and forth it had dreamt up the following:-

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllersWithViews();

var app = builder.Build();

app.UseStaticFiles();

app.UseRouting();

// Route API requests to controllers
app.MapControllerRoute(
    name: "default",
    pattern: "api/{controller}/{action=Index}/{id?}"
);

// Fallback for everything else
app.MapFallback(async context =>
{
    var path = context.Request.Path.Value ?? string.Empty;
    var fileProvider = app.Environment.WebRootFileProvider;

    // Try directory-style fallback: /about → /about/index.html
    var indexPath = Path.Combine(path.Trim('/'), "index.html");
    var indexFile = fileProvider.GetFileInfo(indexPath);

    if (indexFile.Exists)
    {
        context.Response.ContentType = "text/html";
        await context.Response.SendFileAsync(indexFile);
        return;
    }

    // If no match, fallback to root index.html
    var rootFile = fileProvider.GetFileInfo("index.html");
    if (rootFile.Exists)
    {
        context.Response.ContentType = "text/html";
        await context.Response.SendFileAsync(rootFile);
    }
    else
    {
        context.Response.StatusCode = 404;
        await context.Response.WriteAsync("404 Not Found");
    }
});

app.Run();

Well you could do that, sort of, OR you could go with what I figured out by reading the Microsoft documentation for Kestrel:-

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();

var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
// Route API requests to controllers
app.MapControllerRoute(
	name: "default",
	pattern: "api/{controller}/{action=Index}/{id?}"
);
app.UseFileServer();
app.Run();

With ChatGPT no matter what I told it, it just couldn't give me a different answer other than "let's custom write some middle-ware".

Kestrel supports what I wanted out of the box all I had to do was turn it on >>> app.UseFileServer(); Then the content of the wwwroot folder is the root of your static site 🤦‍♂️

AI is not going to replace you IF you are a competent developer that can read documentation. It also helps if you have enough experience to know when someone is feeding you a pile of bollocks.

davehenry.blog by Dave Henry is licensed under CC BY-NC-SA 4.0 CC BY-NC-SA 4.0 button