ee8797c142
Co-authored-by: Copilot <copilot@github.com>
2.5 KiB
2.5 KiB
Getting Started
This guide gets the solution running locally and explains what happens during startup.
What is in this solution
Htmx.ApiDemo: ASP.NET Core app (Minimal API + generated HTMX endpoints)Htmx.SourceGenerator: Roslyn source generator that discovers.htmxfiles and generates endpoint mapping codeHtmx.slnx: solution file at the repository root
Prerequisites
- .NET SDK 10.x (target framework is
net10.0) - Node.js + npm (used for Tailwind CSS compilation during build)
- MongoDB running locally on
mongodb://localhost:27017
First-time setup
From the repository root:
cd Htmx.ApiDemo
npm install
Why this is required:
- The app build runs Tailwind via
npx @tailwindcss/cli ...in a custom MSBuild target. - Without
npm install, build fails because the Tailwind CLI package is missing.
Run the app
From the repository root:
dotnet run --project Htmx.ApiDemo/Htmx.ApiDemo.csproj
Default local URL:
http://localhost:5120
This comes from the launch profile in Htmx.ApiDemo/Properties/launchSettings.json.
Verify it works
- Open
http://localhost:5120 - If you are not authenticated, middleware redirects to
/login - Create an account at
/register - Sign in and navigate the app
What startup config does
Htmx.ApiDemo/Program.cs configures:
- MongoDB DI and index initialization (
EnsureIndexesAsync) - Cookie authentication + authorization
- Antiforgery middleware
- AOT-friendly JSON resolver chain using
AppJsonSerializerContext - Endpoint registration via generated mapping call:
app.MapHtmxApiDemoEndpoints();
Build behavior worth knowing
- Tailwind CSS is compiled before build into
Htmx.ApiDemo/wwwroot/css/output.css .htmxfiles are treated as generator inputs (<AdditionalFiles Include="**/*.htmx" />)- AOT is enabled (
<PublishAot>true</PublishAot>), so reflection-heavy patterns can break publish/runtime
Optional: publish as AOT
dotnet publish Htmx.ApiDemo/Htmx.ApiDemo.csproj -c Release
Use this early to catch AOT issues while developing features.
Troubleshooting
Build fails on Tailwind command
- Run
npm installinsideHtmx.ApiDemo - Confirm
node -vandnpm -vare available
Mongo connection errors
- Confirm MongoDB is running on
localhost:27017 - Confirm
ConnectionStrings:DefaultConnectioninHtmx.ApiDemo/appsettings.json
App keeps redirecting to login
- This is expected for unauthenticated routes
- Register at
/registeror sign in at/login