Skip to content

Commit

Permalink
[Rollout] Production rollout 2025-01-02 part 2 (#4292)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Jan 2, 2025
2 parents 6c14bbd + d5a6174 commit c4178fe
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@page
@model ProductConstructionService.Api.Pages.ErrorModel
@using System.Net
@using Microsoft.AspNetCore.Http
@{
ViewBag.Title = "Error";
}

@if (Model.StatusCode == StatusCodes.Status401Unauthorized)
{
<div>
Please <a href="/Account/SignIn?returnUrl=@WebUtility.UrlEncode(Model.ReturnUrl)">Sign In</a> to use this site. Make sure you have joined the
<a href="https://coreidentity.microsoft.com/manage/Entitlement/entitlement/dotnetesmaes-z54r" target="_blank">dotnetes-maestro-users group</a>.
</div>
}
else
{
<div class="alert alert-danger">
<strong>@Model.StatusCode</strong> @Model.ErrorMessage
</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ProductConstructionService.Api.Pages;

public class ErrorModel : PageModel
{
public new int StatusCode { get; set; }

public string? ErrorMessage { get; set; }

public string? ReturnUrl => HttpContext.Features.Get<IStatusCodeReExecuteFeature>()?.OriginalPath;

public void OnGet(int code)
{
StatusCode = code;
ErrorMessage = HttpContext.Items["ErrorMessage"]?.ToString();
if (string.IsNullOrEmpty(ErrorMessage))
{
ErrorMessage = "Unable to process request.";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ await app.Services.UseLocalWorkItemQueues([
}

// Add security headers
app.UseStatusCodePagesWithReExecute("/Error", "?code={0}");
app.ConfigureSecurityHeaders();

// Map pages and non-API controllers
Expand All @@ -120,9 +121,7 @@ await app.Services.UseLocalWorkItemQueues([
controllers.AllowAnonymous();
}

// UseSpa fails on OPTIONS requests to index.html
// https://github.com/dotnet/aspnetcore/issues/5223#issuecomment-2445336133
app.MapWhen(ctx => ctx.Request.Method != "OPTIONS", a => a.UseSpa(spa =>
app.UseSpa(spa =>
{
if (isDevelopment && Directory.Exists(PcsStartup.LocalCompiledStaticFilesPath))
{
Expand All @@ -135,7 +134,7 @@ await app.Services.UseLocalWorkItemQueues([
{
spa.Options.DefaultPageStaticFileOptions = new StaticFileOptions();
};
}));
});

await app.SetWorkItemProcessorInitialState();

Expand Down

0 comments on commit c4178fe

Please sign in to comment.