Skip to content

Replace nginx with aspnet core hosting#1011

Merged
maartenba merged 1 commit intomainfrom
dh/aspnetcore-hosted
Mar 2, 2026
Merged

Replace nginx with aspnet core hosting#1011
maartenba merged 1 commit intomainfrom
dh/aspnetcore-hosted

Conversation

@damianh
Copy link
Copy Markdown
Member

@damianh damianh commented Feb 26, 2026

Summary

Replace the nginx-based static file serving with an ASP.NET Core application and restructure the repository to separate Astro content from the .NET server.

What changed

Architecture: nginx → ASP.NET Core (server/src/Docs.Web)

  • ASP.NET Core app serves Astro's static output with production-grade caching, response compression, trailing-slash redirects, and custom 404 handling — replicating the existing nginx behavior.
  • Redirect middleware loads redirects.json (generated by Astro build from redirect_from frontmatter) and performs 301 redirects with case-insensitive matching.
  • Dockerfile-free container publishing via dotnet publish /t:PublishContainer targeting aspnet:10.0-alpine.
  • Removed Dockerfile, .dockerignore, and deployment/ (nginx configs).

Repository restructure

  • Moved all Astro source files into an astro/ subdirectory to cleanly separate content from the .NET server.
  • Server projects organized into server/src/ and server/tests/ subdirectories.
  • Astro builds in a Docker container (node:22-slim) to avoid cross-platform npm issues with native modules like sharp and resvg-js.

Build orchestration (build.cs)

  • Single entry point with targets: astro-build, dotnet-build, dotnet-test, container, aspire, link-check, verify-formatting, clean.
  • CI workflows updated to use dotnet build.cs <target>.

Integration tests (server/tests/Docs.Web.Tests)

  • Tests for redirect middleware covering exact match, case-insensitive match, trailing-slash normalization, passthrough for unknown paths, and JSON-body passthrough.
  • Uses WebApplicationFactory with isolated temp wwwroot and test redirects.json.

Local development with .NET Aspire (server/src/Docs.AppHost)

  • dotnet build.cs aspire orchestrates the Astro dev server (port 4321) and the ASP.NET Core app together with OpenTelemetry, health checks, and the Aspire dashboard.

New project structure

├── astro/                          # Astro site (content, components, config)
│   ├── src/content/docs/           # All documentation markdown
│   ├── src/plugins/                # Astro plugins (static-redirects.ts)
│   ├── package.json
│   └── astro.config.mjs
├── server/                         # .NET 10 solution
│   ├── src/
│   │   ├── Docs.Web/               # ASP.NET Core static file server
│   │   ├── Docs.AppHost/           # .NET Aspire orchestrator
│   │   └── Docs.ServiceDefaults/   # Shared OpenTelemetry & health checks
│   ├── tests/
│   │   └── Docs.Web.Tests/         # Integration tests
│   └── Docs.slnx
├── build.cs                        # Build script
└── README.md

Build & run

# Full container build (Astro + .NET publish → OCI image)
dotnet build.cs container

# Local development with Aspire
dotnet build.cs aspire

# Just build Astro
dotnet build.cs astro-build

# Run tests
dotnet build.cs dotnet-test

Files removed

  • Dockerfile, .dockerignore
  • deployment/default.conf, deployment/nginx.conf
  • build.sh

@damianh damianh requested a review from maartenba February 26, 2026 14:17
@damianh damianh force-pushed the dh/aspnetcore-hosted branch 2 times, most recently from 4ba4567 to bf7815f Compare February 26, 2026 15:13
@maartenba
Copy link
Copy Markdown
Member

The nginx redirects being added by static-redirects.ts don't seem to be considered by the ASP.NET Host, can you look into this @damianh ?

@damianh damianh marked this pull request as ready for review February 26, 2026 16:36
@damianh damianh force-pushed the dh/aspnetcore-hosted branch from bf7815f to 4f1b4d5 Compare February 26, 2026 16:40
@damianh
Copy link
Copy Markdown
Member Author

damianh commented Feb 26, 2026

Good catch — fixed. The static-redirects.ts plugin now outputs a redirects.json map instead of the nginx redirect.conf. On the ASP.NET Core side, a redirect middleware in Program.cs loads that JSON at startup and performs 301 redirects with case-insensitive matching. Trailing slashes are normalized before lookup. Also added some tests.

@damianh damianh marked this pull request as draft February 26, 2026 17:15
@damianh damianh force-pushed the dh/aspnetcore-hosted branch from f7f5dbb to 16687e8 Compare February 26, 2026 20:34
Copy link
Copy Markdown
Member

@maartenba maartenba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use writing guidelines/styles

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread server/src/Docs.Web/Program.cs Outdated
@damianh damianh force-pushed the dh/aspnetcore-hosted branch from 16687e8 to c8ceb10 Compare February 26, 2026 22:10
@damianh damianh force-pushed the dh/aspnetcore-hosted branch from c8ceb10 to c0bbc9c Compare February 26, 2026 22:36
@damianh damianh marked this pull request as ready for review February 26, 2026 23:29
@maartenba maartenba added the preview Spins up a preview of the Pull Request for review label Feb 27, 2026
@damianh damianh added preview Spins up a preview of the Pull Request for review and removed preview Spins up a preview of the Pull Request for review labels Feb 27, 2026
@duende-github-bot
Copy link
Copy Markdown

Preview Environment Provisioned

@maartenba maartenba removed the preview Spins up a preview of the Pull Request for review label Feb 27, 2026
@maartenba maartenba self-requested a review February 27, 2026 20:00
Copy link
Copy Markdown
Member

@maartenba maartenba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with it. @damianh let's merge Monday EU AM

@maartenba maartenba merged commit 5287a51 into main Mar 2, 2026
9 checks passed
@maartenba maartenba deleted the dh/aspnetcore-hosted branch March 2, 2026 08:09
@maartenba maartenba added this to the 2026-Q1 milestone Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants