Skip to content

Commit

Permalink
Added default page to handle base route (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjfirth authored Jul 31, 2024
1 parent 6882284 commit a17b612
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
26 changes: 25 additions & 1 deletion src/Dfe.ContentSupport.Web/Controllers/SitemapController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
using Dfe.ContentSupport.Web.Services;
using Dfe.ContentSupport.Web.Models.Mapped;
using Dfe.ContentSupport.Web.Services;
using Dfe.ContentSupport.Web.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Dfe.ContentSupport.Web.Controllers;

[Route("/sitemap")]
[AllowAnonymous]
public class SitemapController(IContentService contentfulService) : Controller
{
[HttpGet]
[Route("/")]
public async Task<IActionResult> Index()
{
var defaultModel = new CsPage
{
Heading = new Models.Heading
{
Title = "Department for Education",
Subtitle = "Content and Support"
}
};


return View(defaultModel);
}

[HttpGet]
[Route("/sitemap.xml")]
public async Task<IActionResult> Sitemap()
{
var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}/";
var sitemap = await contentfulService.GenerateSitemap(baseUrl);
Expand Down
5 changes: 1 addition & 4 deletions src/Dfe.ContentSupport.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void Main(string[] args)
app.UseCookiePolicy();

app.MapControllerRoute(
"sitemap",
"Default",
"sitemap.xml",
new { controller = "Sitemap", action = "Index" }
);
Expand All @@ -52,9 +52,6 @@ public static void Main(string[] args)
pattern: "{controller=Cache}/{action=Clear}"
);

app.MapControllerRoute(
name: "home",
pattern: "{controller=Home}/{action=Home}");

app.MapControllerRoute(
name: "slug",
Expand Down
2 changes: 2 additions & 0 deletions src/Dfe.ContentSupport.Web/Views/Sitemap/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@model CsPage

0 comments on commit a17b612

Please sign in to comment.