|
@@ -201,6 +201,8 @@ namespace FNZCM.ConHost
|
|
VirtualPath = modEnt.Key,
|
|
VirtualPath = modEnt.Key,
|
|
DisplayText = modEnt.Value.DisplayText,
|
|
DisplayText = modEnt.Value.DisplayText,
|
|
DefaultDocument = modEnt.Value.DefaultDocument,
|
|
DefaultDocument = modEnt.Value.DefaultDocument,
|
|
|
|
+ EnableFallbackRoute = modEnt.Value.EnableFallbackRoute,
|
|
|
|
+ HtmlBaseReplace = modEnt.Value.HtmlBaseReplace,
|
|
Files = new Dictionary<string, byte[]>()
|
|
Files = new Dictionary<string, byte[]>()
|
|
};
|
|
};
|
|
|
|
|
|
@@ -371,24 +373,44 @@ namespace FNZCM.ConHost
|
|
{
|
|
{
|
|
context.Response.Redirect("/");
|
|
context.Response.Redirect("/");
|
|
}
|
|
}
|
|
- else if (requestPath.StartsWith("/module/") && pathParts.Count > 1)
|
|
|
|
|
|
+ else if (requestPath.StartsWith("/modules/") && pathParts.Count > 1)
|
|
{
|
|
{
|
|
var moduleKey = pathParts[1];
|
|
var moduleKey = pathParts[1];
|
|
if (Modules.TryGetValue(moduleKey, out var module))
|
|
if (Modules.TryGetValue(moduleKey, out var module))
|
|
{
|
|
{
|
|
var entPath = string.Join("/", pathParts.Skip(2));
|
|
var entPath = string.Join("/", pathParts.Skip(2));
|
|
- if (module.Files.TryGetValue(entPath, out var bin))
|
|
|
|
|
|
+
|
|
|
|
+ void Output(byte[] bin)
|
|
{
|
|
{
|
|
- if (entPath.EndsWith(".js")) context.Response.ContentType = "application/javascript";
|
|
|
|
|
|
+ if (entPath.ToLower().EndsWith(".js")) context.Response.ContentType = "application/javascript";
|
|
|
|
+ else if (module.HtmlBaseReplace != null && entPath.ToLower().EndsWith(".html"))
|
|
|
|
+ {
|
|
|
|
+ //base replace
|
|
|
|
+ var html = Encoding.UTF8.GetString(bin);
|
|
|
|
+ var r = html.Replace(module.HtmlBaseReplace, $"<base href=\"/modules/{moduleKey}/\" />");
|
|
|
|
+ bin = Encoding.UTF8.GetBytes(r);
|
|
|
|
+ }
|
|
|
|
+
|
|
context.Response.OutputStream.Write(bin, 0, bin.Length);
|
|
context.Response.OutputStream.Write(bin, 0, bin.Length);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (module.Files.TryGetValue(entPath, out var bin))
|
|
|
|
+ {
|
|
|
|
+ Output(bin);
|
|
|
|
+ }
|
|
|
|
+ else if (module.EnableFallbackRoute && module.Files.TryGetValue(module.DefaultDocument, out var defBin))
|
|
|
|
+ {
|
|
|
|
+ entPath = module.DefaultDocument;
|
|
|
|
+ Output(defBin);
|
|
|
|
+ }
|
|
else context.Response.StatusCode = 404;
|
|
else context.Response.StatusCode = 404;
|
|
}
|
|
}
|
|
else context.Response.StatusCode = 404;
|
|
else context.Response.StatusCode = 404;
|
|
}
|
|
}
|
|
else if (requestPath == "/" && _defaultModule != null)
|
|
else if (requestPath == "/" && _defaultModule != null)
|
|
{
|
|
{
|
|
- context.Response.Redirect($"/module/{_defaultModule.VirtualPath}/{_defaultModule.DefaultDocument}");
|
|
|
|
|
|
+ if (_defaultModule.EnableFallbackRoute) context.Response.Redirect($"/modules/{_defaultModule.VirtualPath}/");
|
|
|
|
+ else context.Response.Redirect($"/modules/{_defaultModule.VirtualPath}/{_defaultModule.DefaultDocument}");
|
|
}
|
|
}
|
|
else if (requestPath == "/" || requestPath == "/classic-index")
|
|
else if (requestPath == "/" || requestPath == "/classic-index")
|
|
{
|
|
{
|