Skip to content

Commit

Permalink
Fixed an issue that prevent using resource-manager with CDF
Browse files Browse the repository at this point in the history
Closes dnnsoftware#5262

It was a bit of a rabbit hole to go down to figure this one out. Initially I thought the CDF had an error serving javascript with a css mime type. But the underlying issue is that with Stencil.js there is a main script that registers individual components scripts in a different way depending on browser support and loads or not some polyfills accordingly (very efficient). This means that that "entry" file was served by the CDF but the file attempts to load it's "component details" files relative to that path. Unfortunatelly thanks to CDF, that relative path was the CDF handler itselft instead of the path to the other js files. And the CDF defaults to css mime type if it can't figure out the right one.

The Client Dependency Framework does not support javascript modules (because of script relative paths) and there are no plans to add such support according to their repository. Also with this modern way of lazy-loading and with modern http2 having compression and multiplexing, bundling those files is actually a performance hit and not recommended.

Which left us with a couple options:
1. Not take advantage of Js modules by bundling all js files (but this compile target was deprecated by Stencil for the reasons above), so it would have taken quite some time and incur a performance hit instead of a boost.
2. Not use CDF for this project, but this was broken if hosting in a virtual directory (IIS Application under an IIS site folder).

This PR implementes #2 but adds support for ApplicationPath to the existing Request SPA token. This new token support can also be very useful for other SPA modules.

So under normal hosting, this returns `/` but if the site is hosted in a dnn subdirectory it will return '/dnn' (or whataver the web path is for that web application.

I think this will cover all scenarios here.
  • Loading branch information
valadas committed Sep 3, 2022
1 parent 808e2bc commit 0ff4bea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
63 changes: 34 additions & 29 deletions DNN Platform/Library/UI/Modules/Html5/RequestPropertyAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,49 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.UI.Modules.Html5
{
using System.Globalization;
using System.Web;
namespace DotNetNuke.UI.Modules.Html5
{
using System.Globalization;
using System.Web;

using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Tokens;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Tokens;

public class RequestPropertyAccess : IPropertyAccess
{
private readonly HttpRequest _request;
/// <summary>
/// Replaces tokens related to the current http request.
/// </summary>
public class RequestPropertyAccess : IPropertyAccess
{
private readonly HttpRequest request;

/// <summary>
/// Initializes a new instance of the <see cref="RequestPropertyAccess"/> class.
/// </summary>
/// <param name="request"></param>
public RequestPropertyAccess(HttpRequest request)
{
this._request = request;
/// <param name="request">The current http request.</param>
public RequestPropertyAccess(HttpRequest request)
{
this.request = request;
}

/// <inheritdoc/>
public virtual CacheLevel Cacheability
{
get { return CacheLevel.notCacheable; }
public virtual CacheLevel Cacheability
{
get { return CacheLevel.notCacheable; }
}

/// <inheritdoc/>
public string GetProperty(string propertyName, string format, CultureInfo formatProvider, UserInfo accessingUser, Scope accessLevel, ref bool propertyNotFound)
{
switch (propertyName.ToLowerInvariant())
{
case "querystring":
return this._request.QueryString.ToString();
}

propertyNotFound = true;
return string.Empty;
}
}
}
public string GetProperty(string propertyName, string format, CultureInfo formatProvider, UserInfo accessingUser, Scope accessLevel, ref bool propertyNotFound)
{
switch (propertyName.ToLowerInvariant())
{
case "querystring":
return this.request.QueryString.ToString();
case "applicationpath":
return this.request.ApplicationPath;
}

propertyNotFound = true;
return string.Empty;
}
}
}
4 changes: 2 additions & 2 deletions DNN Platform/Modules/ResourceManager/View.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[AntiForgeryToken:True]
[JavaScript:{ path: "~/DesktopModules/ResourceManager/Scripts/dnn-resource-manager/dnn-resource-manager.esm.js", htmlAttributes: { "type":"module" } }]
[JavaScript:{ path: "~/DesktopModules/ResourceManager/Scripts/dnn-resource-manager/dnn-resource-manager.js", htmlAttributes: { "nomodule":"nomodule" } }]
<script type="module" src="[Request:ApplicationPath]/DesktopModules/ResourceManager/Scripts/dnn-resource-manager/dnn-resource-manager.esm.js"></script>
<script nomodule src="[Request:ApplicationPath]/DesktopModules/ResourceManager/Scripts/dnn-resource-manager/dnn-resource-manager.js"></script>
<style type="text/css">
:root {
--dnn-color-primary: #3792ED;
Expand Down

0 comments on commit 0ff4bea

Please sign in to comment.