Skip to content

Commit 522a90d

Browse files
committed
try dynamic fallback routes
1 parent 87e9db5 commit 522a90d

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

TechStacks/Program.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,23 @@
126126
// Fallback for dynamic post routes without a static exported page.
127127
// If a specific post HTML exists, serve it; otherwise serve the generic
128128
// placeholder page that loads the post client-side from the API.
129-
app.MapGet("/posts/{id:long}/{slug}", (long id, string slug, IWebHostEnvironment env) =>
129+
var fallbackRoutes = new Dictionary<string, string>
130130
{
131-
var staticPostPath = Path.Combine(env.WebRootPath, "posts", id.ToString(), $"{slug}.html");
132-
if (File.Exists(staticPostPath))
133-
return Results.File(staticPostPath, "text/html; charset=utf-8");
134-
135-
var placeholderPath = Path.Combine(env.WebRootPath, "posts", "0", "_placeholder", "index.html");
136-
if (File.Exists(placeholderPath))
137-
return Results.File(placeholderPath, "text/html; charset=utf-8");
131+
["/posts/{id:long}/{slug}"] = "posts/0/_placeholder/index.html",
132+
["/tech/{slug}"] = "tech/_placeholder.html",
133+
["/stacks/{slug}"] = "stacks/_placeholder.html",
134+
};
135+
foreach (var route in fallbackRoutes)
136+
{
137+
app.MapGet(route.Key, (HttpContext ctx, IWebHostEnvironment env) =>
138+
{
139+
var placeholderPath = Path.Combine(env.WebRootPath, route.Value);
140+
if (File.Exists(placeholderPath))
141+
return Results.File(placeholderPath, "text/html; charset=utf-8");
138142

139-
return Results.NotFound();
140-
});
143+
return Results.NotFound();
144+
});
145+
}
141146

142147
// GitHub OAuth endpoint
143148
app.MapGet("/auth/github", (

0 commit comments

Comments
 (0)