Properly host static files and set base url

This commit is contained in:
crobibero
2020-09-02 08:03:15 -06:00
parent 0b38ac9a8a
commit 1feee6f95e
7 changed files with 27 additions and 136 deletions

View File

@@ -34,38 +34,23 @@ namespace Jellyfin.Server.Extensions
.UseSwagger(c =>
{
// Custom path requires {documentName}, SwaggerDoc documentName is 'api-docs'
c.RouteTemplate = $"/{baseUrl}{{documentName}}/openapi.json";
c.RouteTemplate = "{documentName}/openapi.json";
c.PreSerializeFilters.Add((swagger, httpReq) =>
{
swagger.Servers = new List<OpenApiServer> { new OpenApiServer { Url = $"{httpReq.Scheme}://{httpReq.Host.Value}{apiDocBaseUrl}" } };
// BaseUrl is empty, ignore
if (apiDocBaseUrl.Length != 0)
{
// Update all relative paths to remove baseUrl.
var updatedPaths = new OpenApiPaths();
foreach (var (key, value) in swagger.Paths)
{
var relativePath = key;
relativePath = relativePath.Remove(0, apiDocBaseUrl.Length);
updatedPaths.Add(relativePath, value);
}
swagger.Paths = updatedPaths;
}
});
})
.UseSwaggerUI(c =>
{
c.DocumentTitle = "Jellyfin API";
c.SwaggerEndpoint($"/{baseUrl}api-docs/openapi.json", "Jellyfin API");
c.RoutePrefix = $"{baseUrl}api-docs/swagger";
c.RoutePrefix = "api-docs/swagger";
})
.UseReDoc(c =>
{
c.DocumentTitle = "Jellyfin API";
c.SpecUrl($"/{baseUrl}api-docs/openapi.json");
c.RoutePrefix = $"{baseUrl}api-docs/redoc";
c.RoutePrefix = "api-docs/redoc";
});
}
}