.NET
Configure ASP.NET Core to work behind Hatch's reverse proxy.
Map your domain
hatch add api.test 5000 --https
Kestrel binding
Make sure Kestrel listens on all interfaces. In launchSettings.json, use 0.0.0.0 instead of localhost:
// Properties/launchSettings.json
{
"profiles": {
"http": {
"commandName": "Project",
"applicationUrl": "http://0.0.0.0:5000"
}
}
}Or via environment variable:
ASPNETCORE_URLS=http://0.0.0.0:5000 dotnet run
Forwarded headers
Enable the forwarded headers middleware so your app sees the correct client IP and protocol:
// Program.cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor
| ForwardedHeaders.XForwardedProto
| ForwardedHeaders.XForwardedHost,
KnownProxies = { IPAddress.Loopback },
});CORS
If a frontend on a different Hatch domain calls your API:
// Program.cs
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.WithOrigins("https://app.test")
.AllowCredentials()
.AllowAnyHeader()
.AllowAnyMethod();
});
});Project config
# .hatch.yaml
domains:
- domain: api.test
port: 5000
https: true