First commit
This commit is contained in:
49
Program.cs
Normal file
49
Program.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Net;
|
||||
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
//my reverse proxy handles HTTPS
|
||||
//app.UseHttpsRedirection();
|
||||
|
||||
|
||||
|
||||
app.MapGet("/{name}", async (string name) =>
|
||||
{
|
||||
string? url = await Redirect.HandleRedirectAsync(name);
|
||||
if(url is not null)
|
||||
return Results.Redirect(url,false,false);
|
||||
else
|
||||
return Results.Text(
|
||||
"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="color-scheme" content="dark light">
|
||||
<title>Not Found</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Not Found</h1>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
,"text/html",System.Text.Encoding.UTF8,404);
|
||||
})
|
||||
.WithName("Redirect");
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user