Extending
A host of your own
The community edition is one host composed of the platform's components. Write your own to add GenHTTP services, put the platform behind a login, wrap every request, set options in code, keep data elsewhere, or run several installations in one process.
The community edition is not a monolith: its whole Program.cs is some thirty lines that put the platform’s components together, the way any GenHTTP application is composed. A host of your own composes them differently - to add routes and services next to the platform, put it behind your login, wrap every request, set options that have no environment variable, or keep data in your infrastructure through integrations.
How a host is put together#
A request passes your concerns, then the runner: apps and previews are its own, everything else goes to the site.
This is the community edition’s src/Hosts/GenHTTP.Lambda.Community/Program.cs:
C#
// the LAMBDA_* variables, with the apps below /lambda/ unless LAMBDA_HOSTING_URL says otherwise
var settings = LambdaSettings.FromEnvironment(LambdaAddressing.Paths, usageReports: true, databases: CommunityDatabase.Offered);
// the image's health check: asks the server running beside it, and starts nothing
if (HealthProbe.IsRequested(args))
{
return await HealthProbe.CheckAsync(settings.Server);
}
// the operator may brand it, and say whom it is for: themselves or an organization
await using var platform = await LambdaPlatform.Create()
.Options(settings.Platform with
{
Branding = true,
Profile = InstallationProfile.Home,
Profiles = [InstallationProfile.Home, InstallationProfile.Enterprise]
})
.Database(CommunityDatabase.Of(settings.Database))
.BuildAsync();
var site = Layout.Create()
.Add(PlatformRoutes.Api, RestApi.Create(platform))
.Add(PlatformRoutes.Mcp, McpServer.Create(platform))
.Add(PlatformRoutes.Editor, Editor.Create(platform))
.Add(PlatformRoutes.Admin, AdminPanel.Create(platform).Add(OperatorMcp.Create(platform)))
.Add(SourcePages.Create(platform))
.Add(LandingPage.Create(platform));
return await LambdaServer.Create(platform)
.Settings(settings)
.Handler(Runner.Create(platform).Site(site))
.RunAsync();
| Part | What it is |
|---|---|
LambdaSettings.FromEnvironment(…) |
reads the LAMBDA_* variables into the platform’s options and the server’s settings - the only place that reads the environment. Pass LambdaAddressing.Paths for the community edition’s default; usageReports: true sends the daily report. |
LambdaPlatform.Create() |
the platform itself: its services, its database, its background jobs. .Options(…), and the integrations with .Database(…), .Files(…), .Secrets(…); BuildAsync() builds and prepares the integrations, migrates the database and reads what the pages need before the first request. |
RestApi, McpServer, Editor, AdminPanel, SourcePages |
the components, each a GenHTTP handler. They link to one another, so each is mounted at its fixed path (PlatformRoutes) and nowhere else. |
OperatorMcp |
the operator’s MCP endpoint at /admin/mcp, put in front of the panel; every other path below /admin stays the panel’s. Leave it out, and there is none. |
LandingPage |
the community edition’s own pages: the front page, /build, /ship, the showcase, robots.txt, the sitemap. |
Runner.Create(platform).Site(site) |
serves the apps - at their domains, subdomains and below /lambda/ - and the drafts’ previews below /features/, and hands every other request to the site. |
LambdaServer.Create(platform) |
the engine, the ports and TLS; it starts the background jobs and seeds the demos once the server listens. |
HealthProbe |
the image’s health check: called with --health, the binary asks the server beside it whether it answers and exits - nothing is built or started. |
Set up a project#
-
Clone the repository at the release you build on, and build the front ends once - the editor, the panel and the pages are bundles the components copy beside your host:
Shell
git clone --branch v0.11.0 https://github.com/MDA2AV/GenHTTP.Lambda.git && cd GenHTTP.Lambda npm install && npm run build # .NET 11 SDK and Node 26 -
Add a project of your own beside the community host, in
src/Hosts/- the repository keeps its projects in folders by role. Referencing the community host brings every component, its front page and the PostgreSQL integration along:src/Hosts/Acme.Lambda/Acme.Lambda.csproj
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <RootNamespace>Acme.Lambda</RootNamespace> <ServerGarbageCollection>true</ServerGarbageCollection> </PropertyGroup> <ItemGroup> <ProjectReference Include="../GenHTTP.Lambda.Community/GenHTTP.Lambda.Community.csproj" /> </ItemGroup> </Project> -
Write its
Program.cs- start from the community edition’s above, and add the recipes below. Run it with the same variables as the image:Shell
LAMBDA_DATA_DIRECTORY=./data LAMBDA_ADMIN_TOKEN=a-long-password \ dotnet run --project src/Hosts/Acme.LambdaIt runs on GenHTTP’s internal engine, as the image does, on any operating system. Apps are not compiled against the assembly of your host, so its types are not theirs to name.
Recipes#
The complete example these recipes come from is at the end of this page. It was tested on 0.6.0, the release whose integrations became asynchronous, and compiles against 0.11.0.
Add services of your own#
The site is an ordinary GenHTTP layout: add any handler at a path the platform does not use - a status endpoint for your monitoring, a webservice, a static site, a reverse proxy to something internal.
C#
var site = Layout.Create()
// … the components, as above …
.Add("status", Inline.Create().Get(() => new Status("ok", DateTime.UtcNow)))
.Add(LandingPage.Create(platform));
public record Status(string State, DateTime Time);
Paths the platform uses: api, mcp, editor, admin, source, lambda, features; for the front page assets, social, build, ship, showcase and the language prefixes of its pages; and the files at the root - robots.txt, sitemap.xml, llms.txt, manifest.json and the icons. Apps never see your routes: on an app’s own host, every path is the app’s.
Put the platform behind a login#
A concern on the site protects every page and API of the platform, while the apps and the drafts’ previews - served by the runner, around the site - stay public:
C#
site.Authentication(BasicAuthentication.Create().Add("team", password));
Everything keeps working for those who send the credentials:
- Browsers ask once, and send them with every request of the editor and the panel.
- Agents send a header - for Claude Code:
claude mcp add --transport http genhttp https://lambda.example.com/mcp --header "Authorization: Basic <base64 of team:password>". Your own agent at/admin/mcpsends it besideX-Admin-Token:--headertwice. - Git takes them in the address or from a credential helper:
https://team:password@lambda.example.com/editor/<editor key>/app.git.
The build agent sends no credentials, so it cannot work behind this login unless you exempt its network in a concern of your own. The image’s health check needs none: the server answering with a 401 is still the server answering. GenHTTP’s authentication module also offers API keys and bearer tokens validated against your identity provider. A login in your reverse proxy, with forward authentication, needs no host of your own - leave /lambda/ and /features/ out of it, or it covers the apps too.
Wrap every request#
Concerns added to the runner run around everything, apps included - for headers, logging or rules of your own. This one keeps every page of an internal installation out of search engines:
C#
public sealed class NoIndex : IConcernBuilder
{
public IConcern Build(IHandler content) => new NoIndexConcern(content);
}
public sealed class NoIndexConcern(IHandler content) : IConcern
{
public IHandler Content => content;
public ValueTask PrepareAsync(IServer server) => content.PrepareAsync(server);
public async ValueTask<IResponse?> HandleAsync(IRequest request)
{
var response = await content.HandleAsync(request);
return response?.Rebuild()
.Header("X-Robots-Tag", "noindex")
.Build();
}
}
C#
.Handler(Runner.Create(platform).Site(site).Add(new NoIndex()))
Set options in code#
LambdaOptions holds more than the environment sets. A host sets the rest with a with expression:
C#
var options = settings.Platform with
{
Branding = true, // the operator may name and brand it
Profile = InstallationProfile.Enterprise, // an organization's, for good
Terms = "Apps built here are for Acme employees and may not keep customer data.",
DefaultTier = LambdaTier.Production // until the panel's Limits say otherwise
};
| Option | Effect |
|---|---|
Branding |
lets the operator give the installation a name and logo in the panel |
Profile |
whom the installation is for: Home by default, Enterprise for an organization’s, Cloud for a public platform - the examples its pages offer and what agents are told about the apps built here (see Settings) |
Profiles |
the profiles the operator may choose among under Settings, Profile among them; none - the default - leaves it Profile |
Terms |
text shown on the create page and to agents, which creating an app has to accept (acceptedTerms) |
DefaultTier, Sandbox, Production, System |
the defaults of the panel’s Limits - the panel’s saved values win |
LegalPages |
the shared pages link to /terms, /privacy and /imprint, which your site then serves |
StartPage |
where the shared pages send people to have an app built, /build by default |
Keep data elsewhere#
Choose the integrations on the platform’s builder:
C#
var builder = LambdaPlatform.Create()
.Options(options)
.Database(CommunityDatabase.Of(settings.Database))
.Secrets(VaultSecrets.Create(address, token));
See Integrations, which builds this secrets integration.
Replace the front page#
Leave out LandingPage.Create(platform) and add your own handler for the root - a StaticWebsite, for one. You then also give up /build, /ship and the showcase pages, and robots.txt and the sitemap of the site; set StartPage to where your site has the workspace instead.
Several installations in one process#
From 0.11.0 on.
An installation per team or per customer does not take a server each. One host can run several of them as handlers of one GenHTTP application: each has its own address, data directory, operator, limits, log and apps, and shares with the others what belongs to nobody - the table of countries, the lists of crawlers, the prerendered pages and the turn to compile. That makes a further installation a matter of a few megabytes rather than of a server.
What they share is a LambdaRuntime, made once and handed to every platform:
C#
await using var runtime = LambdaRuntime.Create()
.Options(new RuntimeOptions { DataDirectory = "/data/runtime", GeoPlaces = false })
.Build();
var platform = await LambdaPlatform.Create()
.Runtime(runtime)
.Options(options) // a data directory, a PublicUrl and a panel password of its own
.BuildAsync();
PlatformHandler takes the place of LambdaServer: it is the platform as a handler, with the same concerns in the same order. Put one per host name into GenHTTP’s virtual hosts, or into a router of your own:
C#
var hosts = VirtualHosts.Create()
.Add("sales.lambda.example.com", PlatformHandler.Create(sales).Handler(Runner.Create(sales).Site(site)))
.Add("support.lambda.example.com", …);
- A host name for each. The pages are at the root of a host, so an installation cannot be mounted below a path. A wildcard DNS record and a wildcard certificate cover them all.
- Start the jobs of a platform with
platform.Start()once it is served. A platform added while the server runs needsawait handler.PrepareAsync(server)first. - The process is your host’s.
LambdaServeris not there to open the ports, to add compression or to stop the server: GenHTTP’sHostand.Defaults()do. The operators see the figures of their installation, and nothing of the process. - The API by reflection -
RestApi.Create(platform).Compiled(false)- where there are many: compiled, it costs every installation a second or two and some megabytes as it starts. - What one of them starts holds up no other installation.
- Taking one away: stop handing it requests, let those under way finish, dispose of the platform, and delete its data directory if it is gone for good. The others go on. The code of its apps stays in memory until the process ends, as .NET cannot unload it.
- One build agent can serve all of them, see One agent for several installations.
src/Hosts/Acme.Lambda.Teams/Program.cs - an installation per team
src/Hosts/Acme.Lambda.Teams/Program.cs
using System.Runtime.InteropServices;
using GenHTTP.Api.Content;
using GenHTTP.Engine.Internal;
using GenHTTP.Lambda;
using GenHTTP.Lambda.Administration;
using GenHTTP.Lambda.Api;
using GenHTTP.Lambda.Community;
using GenHTTP.Lambda.Configuration;
using GenHTTP.Lambda.Editing;
using GenHTTP.Lambda.Execution;
using GenHTTP.Lambda.Mcp;
using GenHTTP.Lambda.Services.Hosting;
using GenHTTP.Lambda.Sources;
using GenHTTP.Modules.Layouting;
using GenHTTP.Modules.Practices;
using GenHTTP.Modules.VirtualHosting;
// the teams and the passwords of their panels: sales=...,support=...
var teams = Environment.GetEnvironmentVariable("ACME_TEAMS")!
.Split(',')
.Select(team => team.Split('=', 2))
.ToDictionary(team => team[0], team => team[1]);
var port = ushort.Parse(Environment.GetEnvironmentVariable("ACME_PORT") ?? "8080");
var domain = Environment.GetEnvironmentVariable("ACME_DOMAIN") ?? "lambda.example.com";
var data = Environment.GetEnvironmentVariable("ACME_DATA") ?? "/data";
// what the process has once: the tables of countries and crawlers, the turn to compile, the compiled apps
await using var runtime = LambdaRuntime.Create()
.Options(new RuntimeOptions { DataDirectory = Path.Combine(data, "runtime"), GeoPlaces = false })
.Build();
var platforms = new List<LambdaPlatform>();
// a request is told apart by the host it is addressed to
var hosts = VirtualHosts.Create();
foreach (var (team, password) in teams)
{
var platform = await LambdaPlatform.Create()
.Runtime(runtime)
.Options(new LambdaOptions
{
DataDirectory = Path.Combine(data, team),
PublicUrl = $"https://{team}.{domain}",
Addressing = LambdaAddressing.Paths,
AdminToken = password,
Profile = InstallationProfile.Enterprise
})
.BuildAsync();
platforms.Add(platform);
hosts.Add($"{team}.{domain}", Serve(platform));
}
var host = Host.Create()
.Handler(hosts)
.Defaults()
.Port(port);
await host.StartAsync();
// the jobs, the demos and the apps that are kept warm, once the server answers
foreach (var platform in platforms)
{
platform.Start();
}
await StoppedAsync();
await host.StopAsync();
foreach (var platform in platforms)
{
await platform.DisposeAsync();
}
static IHandlerBuilder Serve(LambdaPlatform platform)
{
var site = Layout.Create()
.Add(PlatformRoutes.Api, RestApi.Create(platform).Compiled(false))
.Add(PlatformRoutes.Mcp, McpServer.Create(platform))
.Add(PlatformRoutes.Editor, Editor.Create(platform))
.Add(PlatformRoutes.Admin, AdminPanel.Create(platform).Add(OperatorMcp.Create(platform)))
.Add(SourcePages.Create(platform))
.Add(LandingPage.Create(platform));
return PlatformHandler.Create(platform)
.Handler(Runner.Create(platform).Site(site));
}
static async Task StoppedAsync()
{
var stopped = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
using var terminated = PosixSignalRegistration.Create(PosixSignal.SIGTERM, Stop);
using var interrupted = PosixSignalRegistration.Create(PosixSignal.SIGINT, Stop);
await stopped.Task;
void Stop(PosixSignalContext context)
{
context.Cancel = true;
stopped.TrySetResult();
}
}
Its project references the community host, as above, and the module with the virtual hosts. The repository keeps the versions of its packages in one place, so the project names its own: <PackageReference Include="GenHTTP.Modules.VirtualHosting" VersionOverride="11.3.0" />.
Ship it#
The community edition’s Dockerfile builds the front ends and the server in two stages, makes the user and the folders in a third, and copies the results into the runtime image - a chiseled one, without a shell. Copy it for your host and change four things:
COPYthe project files of your own projects with the others, beforedotnet restore;- restore and publish
src/Hosts/Acme.Lambda/Acme.Lambda.csprojinstead of the community host; HEALTHCHECK … CMD ["/app/Acme.Lambda", "--health"];ENTRYPOINT ["./Acme.Lambda"].
Keep the rest - the chiseled runtime, the user lambda (uid and gid 1001) and its folders, LAMBDA_ENGINE=internal and the volume at /data. The health check works because your Program.cs answers --health with HealthProbe before it builds anything, as above.
The complete example#
src/Hosts/Acme.Lambda/Program.cs - the recipes together
src/Hosts/Acme.Lambda/Program.cs
using Acme.Lambda;
using Acme.Lambda.Vault;
using GenHTTP.Lambda;
using GenHTTP.Lambda.Administration;
using GenHTTP.Lambda.Api;
using GenHTTP.Lambda.Community;
using GenHTTP.Lambda.Configuration;
using GenHTTP.Lambda.Data.Entities;
using GenHTTP.Lambda.Editing;
using GenHTTP.Lambda.Execution;
using GenHTTP.Lambda.Mcp;
using GenHTTP.Lambda.Server;
using GenHTTP.Lambda.Services.Hosting;
using GenHTTP.Lambda.Sources;
using GenHTTP.Modules.Authentication;
using GenHTTP.Modules.Functional;
using GenHTTP.Modules.Layouting;
// the LAMBDA_* variables as the community edition reads them - without its daily usage report
var settings = LambdaSettings.FromEnvironment(LambdaAddressing.Paths, databases: CommunityDatabase.Offered);
// the image's health check: asks the server running beside it, and starts nothing
if (HealthProbe.IsRequested(args))
{
return await HealthProbe.CheckAsync(settings.Server);
}
// what has no environment variable: settings of this host's own
var options = settings.Platform with
{
Branding = true,
Profile = InstallationProfile.Enterprise,
Terms = "Apps built here are for Acme employees and may not keep customer data.",
DefaultTier = LambdaTier.Production
};
var builder = LambdaPlatform.Create()
.Options(options)
.Database(CommunityDatabase.Of(settings.Database));
// the secrets in OpenBao, where the environment says so
if (Environment.GetEnvironmentVariable("ACME_BAO_ADDRESS") is { } bao)
{
builder.Secrets(VaultSecrets.Create(bao, Environment.GetEnvironmentVariable("ACME_BAO_TOKEN")!));
}
await using var platform = await builder.BuildAsync();
var site = Layout.Create()
.Add(PlatformRoutes.Api, RestApi.Create(platform))
.Add(PlatformRoutes.Mcp, McpServer.Create(platform))
.Add(PlatformRoutes.Editor, Editor.Create(platform))
.Add(PlatformRoutes.Admin, AdminPanel.Create(platform).Add(OperatorMcp.Create(platform)))
.Add(SourcePages.Create(platform))
.Add("status", Inline.Create().Get(() => new Status("ok", DateTime.UtcNow)))
.Add(LandingPage.Create(platform));
// the platform's pages for the team only; the apps stay public
if (Environment.GetEnvironmentVariable("ACME_TEAM_PASSWORD") is { } password)
{
site.Authentication(BasicAuthentication.Create().Add("team", password));
}
return await LambdaServer.Create(platform)
.Settings(settings)
.Handler(Runner.Create(platform).Site(site).Add(new NoIndex()))
.RunAsync();
namespace Acme.Lambda
{
public record Status(string State, DateTime Time);
}
The concern is in NoIndex.cs beside it, as shown above with using GenHTTP.Api.Content;, using GenHTTP.Api.Infrastructure; and using GenHTTP.Api.Protocol;; the secrets integration is a project of its own, src/Integrations/Acme.Lambda.Vault, referenced by this one.