v14: Rewrite static assets for the backoffice (#14472)

* add extension method to rewrite requests meant for backoffice static assets

* add backoffice rewrites to application builder

* embed the umbraco hash into the static assets requested on the backoffice

* Added a IStaticFileHostGenerator so its possible to replace our logic

* add docs and ensure the path is uniform with single slashes

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Jacob Overgaard
2023-06-28 14:55:19 +02:00
committed by GitHub
parent 7265d5c3be
commit ddca33337b
7 changed files with 233 additions and 162 deletions

View File

@@ -1,24 +1,19 @@
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Options
@using Umbraco.Cms.Core.Configuration
@using Umbraco.Cms.Core.Configuration.Models
@using Umbraco.Cms.Core.Hosting
@using Umbraco.Cms.Core.WebAssets
@using Umbraco.Cms.Web.Common.Hosting
@using Umbraco.Extensions
@using UrlHelperExtensions = Umbraco.Extensions.UrlHelperExtensions
@inject IUmbracoVersion UmbracoVersion
@inject IHostingEnvironment HostingEnvironment
@inject IOptions<GlobalSettings> GlobalSettings
@inject IRuntimeMinifier RuntimeMinifier
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@inject IStaticFilePathGenerator StaticFilePathGenerator
@{
var backOfficePath = GlobalSettings.Value.GetBackOfficePath(HostingEnvironment);
var cacheBust = "?umb__rnd=" + UrlHelperExtensions.GetCacheBustHash(HostingEnvironment, UmbracoVersion, RuntimeMinifier);
var backofficeAssetsPath = StaticFilePathGenerator.BackofficeAssetsPath;
}
@functions {
private static string ImportMapValue(string alias, string path, string cacheBust) => $"\"{alias}\": \"{path}{cacheBust}\"";
private static string ImportMapValue(string alias, string path) => $"\"{alias}\": \"{path}\"";
}
<!DOCTYPE html>
@@ -26,94 +21,95 @@
<head>
<base href="@backOfficePath.EnsureEndsWith('/')" />
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="~/umbraco/backoffice/assets/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="@backofficeAssetsPath/assets/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Umbraco</title>
<link rel="stylesheet" href="~/umbraco/backoffice/css/umb-css.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/umbraco/backoffice/css/uui-css.css" asp-append-version="true"/>
<link rel="stylesheet" href="@backofficeAssetsPath/css/umb-css.css" />
<link rel="stylesheet" href="@backofficeAssetsPath/css/uui-css.css" />
<script type="importmap">
{
"imports": {
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/uui", "/umbraco/backoffice/external/uui/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/lit", "/umbraco/backoffice/external/lit/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/openid", "/umbraco/backoffice/external/openid/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/rxjs", "/umbraco/backoffice/external/rxjs/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/router-slot", "/umbraco/backoffice/external/router-slot/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/uuid", "/umbraco/backoffice/external/uuid/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/lodash", "/umbraco/backoffice/external/lodash/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/monaco-editor", "/umbraco/backoffice/external/monaco-editor/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/tinymce", "/umbraco/backoffice/external/tinymce/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/uui", backofficeAssetsPath + "/external/uui/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/lit", backofficeAssetsPath + "/external/lit/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/openid", backofficeAssetsPath + "/external/openid/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/rxjs", backofficeAssetsPath + "/external/rxjs/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/router-slot", backofficeAssetsPath + "/external/router-slot/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/uuid", backofficeAssetsPath + "/external/uuid/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/lodash", backofficeAssetsPath + "/external/lodash/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/monaco-editor", backofficeAssetsPath + "/external/monaco-editor/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/tinymce", backofficeAssetsPath + "/external/tinymce/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/backend-api", "/umbraco/backoffice/external/backend-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/context-api", "/umbraco/backoffice/libs/context-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/controller-api", "/umbraco/backoffice/libs/controller-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/element-api", "/umbraco/backoffice/libs/element-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/extension-api", "/umbraco/backoffice/libs/extension-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/observable-api", "/umbraco/backoffice/libs/observable-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/backend-api", backofficeAssetsPath + "/external/backend-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/class-api", backofficeAssetsPath + "/libs/class-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/context-api", backofficeAssetsPath + "/libs/context-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/controller-api", backofficeAssetsPath + "/libs/controller-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/element-api", backofficeAssetsPath + "/libs/element-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/extension-api", backofficeAssetsPath + "/libs/extension-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/observable-api", backofficeAssetsPath + "/libs/observable-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/auth", "/umbraco/backoffice/shared/auth/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/context", "/umbraco/backoffice/shared/context/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/events", "/umbraco/backoffice/shared/umb-events/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/icon", "/umbraco/backoffice/shared/icon-registry/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/models", "/umbraco/backoffice/shared/models/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/repository", "/umbraco/backoffice/shared/repository/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/resources", "/umbraco/backoffice/shared/resources/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/router", "/umbraco/backoffice/shared/router/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/utils", "/umbraco/backoffice/shared/utils/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/auth", backofficeAssetsPath + "/shared/auth/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/context", backofficeAssetsPath + "/shared/context/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/events", backofficeAssetsPath + "/shared/umb-events/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/icon", backofficeAssetsPath + "/shared/icon-registry/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/models", backofficeAssetsPath + "/shared/models/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/repository", backofficeAssetsPath + "/shared/repository/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/resources", backofficeAssetsPath + "/shared/resources/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/router", backofficeAssetsPath + "/shared/router/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/utils", backofficeAssetsPath + "/shared/utils/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/internal/lit-element", "/umbraco/backoffice/shared/lit-element/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/internal/modal", "/umbraco/backoffice/shared/modal/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/internal/lit-element", backofficeAssetsPath + "/shared/lit-element/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/internal/modal", backofficeAssetsPath + "/shared/modal/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/action", "/umbraco/backoffice/packages/core/action/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/collection", "/umbraco/backoffice/packages/core/collection/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/components", "/umbraco/backoffice/packages/core/components/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/content-type", "/umbraco/backoffice/packages/core/content-type/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/debug", "/umbraco/backoffice/packages/core/debug/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/entity-action", "/umbraco/backoffice/packages/core/entity-action/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/entity-bulk-action", "/umbraco/backoffice/packages/core/entity-bulk-action/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/extension-registry", "/umbraco/backoffice/packages/core/extension-registry/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/id", "/umbraco/backoffice/packages/core/id/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/macro", "/umbraco/backoffice/packages/core/macro/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/menu", "/umbraco/backoffice/packages/core/menu/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/modal", "/umbraco/backoffice/packages/core/modal/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/notification", "/umbraco/backoffice/packages/core/notification/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/picker-input", "/umbraco/backoffice/packages/core/picker-input/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/section", "/umbraco/backoffice/packages/core/section/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/sorter", "/umbraco/backoffice/packages/core/sorter/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/store", "/umbraco/backoffice/packages/core/store/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/tree", "/umbraco/backoffice/packages/core/tree/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/variant", "/umbraco/backoffice/packages/core/variant/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/workspace", "/umbraco/backoffice/packages/core/workspace/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/property-editor", "/umbraco/backoffice/packages/core/property-editor/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/action", backofficeAssetsPath + "/packages/core/action/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/collection", backofficeAssetsPath + "/packages/core/collection/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/components", backofficeAssetsPath + "/packages/core/components/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/content-type", backofficeAssetsPath + "/packages/core/content-type/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/debug", backofficeAssetsPath + "/packages/core/debug/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/entity-action", backofficeAssetsPath + "/packages/core/entity-action/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/entity-bulk-action", backofficeAssetsPath + "/packages/core/entity-bulk-action/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/extension-registry", backofficeAssetsPath + "/packages/core/extension-registry/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/id", backofficeAssetsPath + "/packages/core/id/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/macro", backofficeAssetsPath + "/packages/core/macro/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/menu", backofficeAssetsPath + "/packages/core/menu/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/modal", backofficeAssetsPath + "/packages/core/modal/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/notification", backofficeAssetsPath + "/packages/core/notification/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/picker-input", backofficeAssetsPath + "/packages/core/picker-input/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/section", backofficeAssetsPath + "/packages/core/section/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/sorter", backofficeAssetsPath + "/packages/core/sorter/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/store", backofficeAssetsPath + "/packages/core/store/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/tree", backofficeAssetsPath + "/packages/core/tree/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/variant", backofficeAssetsPath + "/packages/core/variant/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/workspace", backofficeAssetsPath + "/packages/core/workspace/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/property-editor", backofficeAssetsPath + "/packages/core/property-editor/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document", "/umbraco/backoffice/packages/documents/documents/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document-blueprint", "/umbraco/backoffice/packages/documents/document-blueprints/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document-type", "/umbraco/backoffice/packages/documents/document-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/media", "/umbraco/backoffice/packages/media/media/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/media-type", "/umbraco/backoffice/packages/media/media-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member", "/umbraco/backoffice/packages/members/members/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member-group", "/umbraco/backoffice/packages/members/member-groups/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member-type", "/umbraco/backoffice/packages/members/member-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/package", "/umbraco/backoffice/packages/packages/package/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document", backofficeAssetsPath + "/packages/documents/documents/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document-blueprint", backofficeAssetsPath + "/packages/documents/document-blueprints/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document-type", backofficeAssetsPath + "/packages/documents/document-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/media", backofficeAssetsPath + "/packages/media/media/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/media-type", backofficeAssetsPath + "/packages/media/media-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member", backofficeAssetsPath + "/packages/members/members/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member-group", backofficeAssetsPath + "/packages/members/member-groups/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member-type", backofficeAssetsPath + "/packages/members/member-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/package", backofficeAssetsPath + "/packages/packages/package/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/data-type", "/umbraco/backoffice/packages/settings/data-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/language", "/umbraco/backoffice/packages/settings/languages/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/relation-type", "/umbraco/backoffice/packages/settings/relation-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/themes", "/umbraco/backoffice/packages/settings/themes/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/tags", "/umbraco/backoffice/packages/tags/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/partial-view", "/umbraco/backoffice/packages/templating/partial-views/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/stylesheet", "/umbraco/backoffice/packages/templating/stylesheets/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/template", "/umbraco/backoffice/packages/templating/templates/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/data-type", backofficeAssetsPath + "/packages/settings/data-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/language", backofficeAssetsPath + "/packages/settings/languages/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/relation-type", backofficeAssetsPath + "/packages/settings/relation-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/themes", backofficeAssetsPath + "/packages/settings/themes/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/tags", backofficeAssetsPath + "/packages/tags/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/partial-view", backofficeAssetsPath + "/packages/templating/partial-views/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/stylesheet", backofficeAssetsPath + "/packages/templating/stylesheets/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/template", backofficeAssetsPath + "/packages/templating/templates/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/user-group", "/umbraco/backoffice/packages/users/user-groups/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/current-user", "/umbraco/backoffice/packages/users/current-user/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/users", "/umbraco/backoffice/packages/users/users/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/user-group", backofficeAssetsPath + "/packages/users/user-groups/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/current-user", backofficeAssetsPath + "/packages/users/current-user/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/users", backofficeAssetsPath + "/packages/users/users/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/code-editor", "/umbraco/backoffice/packages/templating/code-editor/index.js", cacheBust))
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/code-editor", backofficeAssetsPath + "/packages/templating/code-editor/index.js"))
}
}
</script>
<script type="module" src="~/umbraco/backoffice/apps/app/app.element.js" asp-append-version="true"></script>
<script type="module" src="@backofficeAssetsPath/apps/app/app.element.js"></script>
</head>
<body class="uui-font uui-text" style="margin: 0; padding: 0; overflow: hidden">
<umb-app></umb-app>

View File

@@ -1,24 +1,19 @@
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.Extensions.Options
@using Umbraco.Cms.Core.Configuration
@using Umbraco.Cms.Core.Configuration.Models
@using Umbraco.Cms.Core.Hosting
@using Umbraco.Cms.Core.WebAssets
@using Umbraco.Cms.Web.Common.Hosting
@using Umbraco.Extensions
@using UrlHelperExtensions = Umbraco.Extensions.UrlHelperExtensions
@inject IUmbracoVersion UmbracoVersion
@inject IHostingEnvironment HostingEnvironment
@inject IOptions<GlobalSettings> GlobalSettings
@inject IRuntimeMinifier RuntimeMinifier
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@inject IStaticFilePathGenerator StaticFilePathGenerator
@{
var backOfficePath = GlobalSettings.Value.GetBackOfficePath(HostingEnvironment);
var cacheBust = "?umb__rnd=" + UrlHelperExtensions.GetCacheBustHash(HostingEnvironment, UmbracoVersion, RuntimeMinifier);
var backofficeAssetsPath = StaticFilePathGenerator.BackofficeAssetsPath;
}
@functions {
private static string ImportMapValue(string alias, string path, string cacheBust) => $"\"{alias}\": \"{path}{cacheBust}\"";
private static string ImportMapValue(string alias, string path) => $"\"{alias}\": \"{path}\"";
}
<!DOCTYPE html>
@@ -26,94 +21,95 @@
<head>
<base href="@backOfficePath.EnsureEndsWith('/')" />
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="~/umbraco/backoffice/assets/favicon.svg" />
<link rel="icon" type="image/svg+xml" href="@backofficeAssetsPath/assets/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Umbraco</title>
<link rel="stylesheet" href="~/umbraco/backoffice/css/umb-css.css" asp-append-version="true"/>
<link rel="stylesheet" href="~/umbraco/backoffice/css/uui-css.css" asp-append-version="true"/>
<link rel="stylesheet" href="@backofficeAssetsPath/css/umb-css.css" />
<link rel="stylesheet" href="@backofficeAssetsPath/css/uui-css.css" />
<script type="importmap">
{
"imports": {
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/uui", "/umbraco/backoffice/external/uui/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/lit", "/umbraco/backoffice/external/lit/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/openid", "/umbraco/backoffice/external/openid/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/rxjs", "/umbraco/backoffice/external/rxjs/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/router-slot", "/umbraco/backoffice/external/router-slot/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/uuid", "/umbraco/backoffice/external/uuid/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/lodash", "/umbraco/backoffice/external/lodash/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/monaco-editor", "/umbraco/backoffice/external/monaco-editor/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/tinymce", "/umbraco/backoffice/external/tinymce/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/uui", backofficeAssetsPath + "/external/uui/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/lit", backofficeAssetsPath + "/external/lit/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/openid", backofficeAssetsPath + "/external/openid/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/rxjs", backofficeAssetsPath + "/external/rxjs/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/router-slot", backofficeAssetsPath + "/external/router-slot/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/uuid", backofficeAssetsPath + "/external/uuid/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/lodash", backofficeAssetsPath + "/external/lodash/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/monaco-editor", backofficeAssetsPath + "/external/monaco-editor/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/external/tinymce", backofficeAssetsPath + "/external/tinymce/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/backend-api", "/umbraco/backoffice/external/backend-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/context-api", "/umbraco/backoffice/libs/context-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/controller-api", "/umbraco/backoffice/libs/controller-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/element-api", "/umbraco/backoffice/libs/element-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/extension-api", "/umbraco/backoffice/libs/extension-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/observable-api", "/umbraco/backoffice/libs/observable-api/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/backend-api", backofficeAssetsPath + "/external/backend-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/class-api", backofficeAssetsPath + "/libs/class-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/context-api", backofficeAssetsPath + "/libs/context-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/controller-api", backofficeAssetsPath + "/libs/controller-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/element-api", backofficeAssetsPath + "/libs/element-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/extension-api", backofficeAssetsPath + "/libs/extension-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/observable-api", backofficeAssetsPath + "/libs/observable-api/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/auth", "/umbraco/backoffice/shared/auth/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/context", "/umbraco/backoffice/shared/context/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/events", "/umbraco/backoffice/shared/umb-events/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/icon", "/umbraco/backoffice/shared/icon-registry/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/models", "/umbraco/backoffice/shared/models/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/repository", "/umbraco/backoffice/shared/repository/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/resources", "/umbraco/backoffice/shared/resources/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/router", "/umbraco/backoffice/shared/router/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/utils", "/umbraco/backoffice/shared/utils/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/auth", backofficeAssetsPath + "/shared/auth/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/context", backofficeAssetsPath + "/shared/context/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/events", backofficeAssetsPath + "/shared/umb-events/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/icon", backofficeAssetsPath + "/shared/icon-registry/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/models", backofficeAssetsPath + "/shared/models/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/repository", backofficeAssetsPath + "/shared/repository/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/resources", backofficeAssetsPath + "/shared/resources/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/router", backofficeAssetsPath + "/shared/router/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/utils", backofficeAssetsPath + "/shared/utils/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/internal/lit-element", "/umbraco/backoffice/shared/lit-element/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/internal/modal", "/umbraco/backoffice/shared/modal/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/internal/lit-element", backofficeAssetsPath + "/shared/lit-element/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/internal/modal", backofficeAssetsPath + "/shared/modal/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/action", "/umbraco/backoffice/packages/core/action/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/collection", "/umbraco/backoffice/packages/core/collection/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/components", "/umbraco/backoffice/packages/core/components/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/content-type", "/umbraco/backoffice/packages/core/content-type/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/debug", "/umbraco/backoffice/packages/core/debug/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/entity-action", "/umbraco/backoffice/packages/core/entity-action/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/entity-bulk-action", "/umbraco/backoffice/packages/core/entity-bulk-action/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/extension-registry", "/umbraco/backoffice/packages/core/extension-registry/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/id", "/umbraco/backoffice/packages/core/id/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/macro", "/umbraco/backoffice/packages/core/macro/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/menu", "/umbraco/backoffice/packages/core/menu/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/modal", "/umbraco/backoffice/packages/core/modal/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/notification", "/umbraco/backoffice/packages/core/notification/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/picker-input", "/umbraco/backoffice/packages/core/picker-input/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/section", "/umbraco/backoffice/packages/core/section/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/sorter", "/umbraco/backoffice/packages/core/sorter/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/store", "/umbraco/backoffice/packages/core/store/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/tree", "/umbraco/backoffice/packages/core/tree/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/variant", "/umbraco/backoffice/packages/core/variant/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/workspace", "/umbraco/backoffice/packages/core/workspace/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/property-editor", "/umbraco/backoffice/packages/core/property-editor/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/action", backofficeAssetsPath + "/packages/core/action/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/collection", backofficeAssetsPath + "/packages/core/collection/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/components", backofficeAssetsPath + "/packages/core/components/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/content-type", backofficeAssetsPath + "/packages/core/content-type/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/debug", backofficeAssetsPath + "/packages/core/debug/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/entity-action", backofficeAssetsPath + "/packages/core/entity-action/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/entity-bulk-action", backofficeAssetsPath + "/packages/core/entity-bulk-action/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/extension-registry", backofficeAssetsPath + "/packages/core/extension-registry/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/id", backofficeAssetsPath + "/packages/core/id/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/macro", backofficeAssetsPath + "/packages/core/macro/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/menu", backofficeAssetsPath + "/packages/core/menu/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/modal", backofficeAssetsPath + "/packages/core/modal/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/notification", backofficeAssetsPath + "/packages/core/notification/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/picker-input", backofficeAssetsPath + "/packages/core/picker-input/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/section", backofficeAssetsPath + "/packages/core/section/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/sorter", backofficeAssetsPath + "/packages/core/sorter/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/store", backofficeAssetsPath + "/packages/core/store/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/tree", backofficeAssetsPath + "/packages/core/tree/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/variant", backofficeAssetsPath + "/packages/core/variant/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/workspace", backofficeAssetsPath + "/packages/core/workspace/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/property-editor", backofficeAssetsPath + "/packages/core/property-editor/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document", "/umbraco/backoffice/packages/documents/documents/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document-blueprint", "/umbraco/backoffice/packages/documents/document-blueprints/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document-type", "/umbraco/backoffice/packages/documents/document-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/media", "/umbraco/backoffice/packages/media/media/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/media-type", "/umbraco/backoffice/packages/media/media-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member", "/umbraco/backoffice/packages/members/members/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member-group", "/umbraco/backoffice/packages/members/member-groups/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member-type", "/umbraco/backoffice/packages/members/member-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/package", "/umbraco/backoffice/packages/packages/package/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document", backofficeAssetsPath + "/packages/documents/documents/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document-blueprint", backofficeAssetsPath + "/packages/documents/document-blueprints/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/document-type", backofficeAssetsPath + "/packages/documents/document-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/media", backofficeAssetsPath + "/packages/media/media/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/media-type", backofficeAssetsPath + "/packages/media/media-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member", backofficeAssetsPath + "/packages/members/members/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member-group", backofficeAssetsPath + "/packages/members/member-groups/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/member-type", backofficeAssetsPath + "/packages/members/member-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/package", backofficeAssetsPath + "/packages/packages/package/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/data-type", "/umbraco/backoffice/packages/settings/data-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/language", "/umbraco/backoffice/packages/settings/languages/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/relation-type", "/umbraco/backoffice/packages/settings/relation-types/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/themes", "/umbraco/backoffice/packages/settings/themes/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/tags", "/umbraco/backoffice/packages/tags/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/partial-view", "/umbraco/backoffice/packages/templating/partial-views/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/stylesheet", "/umbraco/backoffice/packages/templating/stylesheets/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/template", "/umbraco/backoffice/packages/templating/templates/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/data-type", backofficeAssetsPath + "/packages/settings/data-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/language", backofficeAssetsPath + "/packages/settings/languages/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/relation-type", backofficeAssetsPath + "/packages/settings/relation-types/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/themes", backofficeAssetsPath + "/packages/settings/themes/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/tags", backofficeAssetsPath + "/packages/tags/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/partial-view", backofficeAssetsPath + "/packages/templating/partial-views/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/stylesheet", backofficeAssetsPath + "/packages/templating/stylesheets/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/template", backofficeAssetsPath + "/packages/templating/templates/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/user-group", "/umbraco/backoffice/packages/users/user-groups/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/current-user", "/umbraco/backoffice/packages/users/current-user/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/users", "/umbraco/backoffice/packages/users/users/index.js", cacheBust)),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/user-group", backofficeAssetsPath + "/packages/users/user-groups/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/current-user", backofficeAssetsPath + "/packages/users/current-user/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/users", backofficeAssetsPath + "/packages/users/users/index.js")),
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/code-editor", "/umbraco/backoffice/packages/templating/code-editor/index.js", cacheBust))
@Html.Raw(ImportMapValue("@umbraco-cms/backoffice/code-editor", backofficeAssetsPath + "/packages/templating/code-editor/index.js"))
}
}
</script>
<script type="module" src="~/umbraco/backoffice/apps/app/app.element.js" asp-append-version="true"></script>
<script type="module" src="@backofficeAssetsPath/apps/app/app.element.js"></script>
</head>
<body class="uui-font uui-text" style="margin: 0; padding: 0; overflow: hidden">
<umb-app></umb-app>

View File

@@ -20,6 +20,7 @@ using Umbraco.Cms.Web.BackOffice.Security;
using Umbraco.Cms.Web.BackOffice.Services;
using Umbraco.Cms.Web.BackOffice.SignalR;
using Umbraco.Cms.Web.BackOffice.Trees;
using Umbraco.Cms.Web.Common.Hosting;
namespace Umbraco.Extensions;
@@ -81,6 +82,7 @@ public static partial class UmbracoBuilderExtensions
public static IUmbracoBuilder AddBackOfficeCore(this IUmbracoBuilder builder)
{
builder.Services.AddUnique<IStaticFilePathGenerator, UmbracoStaticFilePathGenerator>();
builder.Services.AddSingleton<KeepAliveMiddleware>();
builder.Services.ConfigureOptions<ConfigureGlobalOptionsForKeepAliveMiddlware>();
builder.Services.AddSingleton<ServerVariablesParser>();

View File

@@ -73,6 +73,8 @@ public class UmbracoApplicationBuilder : IUmbracoApplicationBuilder, IUmbracoEnd
AppBuilder.UseUmbracoMediaFileProvider();
AppBuilder.UseUmbracoBackOfficeRewrites();
AppBuilder.UseStaticFiles();
AppBuilder.UseUmbracoPluginsStaticFiles();

View File

@@ -1,6 +1,7 @@
using Dazinator.Extensions.FileProviders.PrependBasePath;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
@@ -14,6 +15,7 @@ using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Logging.Serilog.Enrichers;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.Common.ApplicationBuilder;
using Umbraco.Cms.Web.Common.Hosting;
using Umbraco.Cms.Web.Common.Media;
using Umbraco.Cms.Web.Common.Middleware;
using Umbraco.Cms.Web.Common.Plugins;
@@ -166,4 +168,20 @@ public static class ApplicationBuilderExtensions
return app;
}
/// <summary>
/// Configure a virtual path with IApplicationBuilder.UseRewriter for backoffice assets to allow cache-busting using the url
/// /umbraco/backoffice/!cache-busting-id!/assets/index.js => /umbraco/backoffice/assets/index.js.
/// </summary>
public static IApplicationBuilder UseUmbracoBackOfficeRewrites(this IApplicationBuilder builder)
{
IStaticFilePathGenerator staticFilePathGenerator = builder.ApplicationServices.GetRequiredService<IStaticFilePathGenerator>();
var backofficeAssetsPath = staticFilePathGenerator.BackofficeAssetsPath.TrimStart("/").EnsureEndsWith("/");
builder.UseRewriter(new RewriteOptions()
// The destination needs to be hardcoded to "/umbraco/backoffice" because this is where they are located in the Umbraco.Cms.StaticAssets RCL
.AddRewrite(@"^" + backofficeAssetsPath + "(.+)", "/umbraco/backoffice/$1", true));
return builder;
}
}

View File

@@ -0,0 +1,12 @@
namespace Umbraco.Cms.Web.Common.Hosting;
/// <summary>
/// Umbraco-specific settings for static files from the Umbraco.Cms.StaticAssets RCL.
/// </summary>
public interface IStaticFilePathGenerator
{
/// <summary>
/// The virtual path of the static assets used in the Backoffice.
/// </summary>
string BackofficeAssetsPath { get; }
}

View File

@@ -0,0 +1,45 @@
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.WebAssets;
using Umbraco.Cms.Web.Common.Hosting;
using Umbraco.Extensions;
public class UmbracoStaticFilePathGenerator : IStaticFilePathGenerator
{
private string? _backofficeAssetsPath;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IUmbracoVersion _umbracoVersion;
private readonly IRuntimeMinifier _runtimeMinifier;
private readonly IOptions<GlobalSettings> _globalSettings;
public UmbracoStaticFilePathGenerator(IHostingEnvironment hostingEnvironment, IUmbracoVersion umbracoVersion, IRuntimeMinifier runtimeMinifier, IOptions<GlobalSettings> globalSettings)
{
_hostingEnvironment = hostingEnvironment;
_umbracoVersion = umbracoVersion;
_runtimeMinifier = runtimeMinifier;
_globalSettings = globalSettings;
}
/// <summary>
/// Get the virtual path for the Backoffice assets coming from the Umbraco.Cms.StaticAssets RCL.
/// The path will contain a generated SHA1 hash that is based on a number of parameters including the UmbracoVersion and runtime minifier.
/// </summary>
/// <example>/umbraco/backoffice/addf120b430021c36c232c99ef8d926aea2acd6b</example>
/// <see cref="UrlHelperExtensions.GetCacheBustHash"/>
public string BackofficeAssetsPath
{
get
{
if (_backofficeAssetsPath is null)
{
var umbracoHash = UrlHelperExtensions.GetCacheBustHash(_hostingEnvironment, _umbracoVersion, _runtimeMinifier);
var backOfficePath = _globalSettings.Value.GetBackOfficePath(_hostingEnvironment);
_backofficeAssetsPath = backOfficePath.EnsureEndsWith('/') + "backoffice/" + umbracoHash;
}
return _backofficeAssetsPath;
}
}
}