Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/SwaggerDiff.AspNetCore/Extensions/SwaggerDiffExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,8 @@ public static WebApplication UseSwaggerDiff(this WebApplication app)
await using var stream = Assembly.GetManifestResourceStream(SwaggerDiffIndexResource);
if (stream != null)
{
// Inside a Map() branch, PathBase includes the RoutePrefix.
// Strip it to recover the application's actual PathBase so the
// frontend can prefix API calls correctly.
var branchPathBase = context.Request.PathBase.Value?.TrimEnd('/') ?? "";
var normalizedPrefix = options.RoutePrefix.TrimEnd('/');
var pathBase = branchPathBase.EndsWith(normalizedPrefix, StringComparison.OrdinalIgnoreCase)
? branchPathBase[..^normalizedPrefix.Length]
: branchPathBase;
pathBase = pathBase.TrimEnd('/');

using var reader = new StreamReader(stream);
var html = (await reader.ReadToEndAsync())
.Replace("{{PATH_BASE}}", pathBase);

context.Response.ContentType = "text/html";
await context.Response.WriteAsync(html);
await stream.CopyToAsync(context.Response.Body);
return;
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/SwaggerDiff.AspNetCore/wwwroot/swagger-diff/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
<body>
<div class="container">
<div class="header-row">
<a href="{{PATH_BASE}}/swagger" class="back-link">&#128281; Back to Swagger</a>
<a id="backLink" href="/swagger" class="back-link">&#128281; Back to Swagger</a>
<h2 class="title">Swagger Diff Viewer</h2>
</div>

Expand Down Expand Up @@ -241,8 +241,11 @@ <h2 class="title">Swagger Diff Viewer</h2>
<div id="toast" class="toast"></div>

<script>
// PathBase injected at serve-time (empty string when no reverse proxy prefix)
const pathBase = '{{PATH_BASE}}';
// Derive PathBase from the current URL at runtime.
// This page is served at {pathBase}/swagger-diff, so everything
// before the last segment is the application's PathBase.
const pagePath = window.location.pathname.replace(/\/+$/, '');
const pathBase = pagePath.substring(0, pagePath.lastIndexOf('/'));

// State
let versions = [];
Expand Down Expand Up @@ -416,6 +419,9 @@ <h2 class="title">Swagger Diff Viewer</h2>

// Parse URL params and initialize
function init() {
// Update back link with PathBase
document.getElementById('backLink').href = pathBase + '/swagger';

const params = new URLSearchParams(window.location.search);
const oldParam = params.get('old');
const newParam = params.get('new');
Expand Down