source: TFP-WebServer/WebServer/src/WebMod.cs@ 474

Last change on this file since 474 was 463, checked in by alloc, 16 months ago

21.1.16.0 release
Completed OpenAPI specs
Add support to path handlers to register OpenAPI specs
Fixed ItemIconHandler throwing error when requested path contains no dot

File size: 1.5 KB
RevLine 
[391]1using System.IO;
[402]2using Webserver.FileCache;
[391]3using Webserver.UrlHandlers;
4
5namespace Webserver {
6 public class WebMod {
7 private const string modsBaseUrl = "/webmods/";
8 private const string reactBundleName = "bundle.js";
9 private const string stylingFileName = "styling.css";
10
11 public readonly Mod ParentMod;
[463]12 /// <summary>
13 /// Absolute web path to the mod web root, e.g. "/webmods/myMod/"
14 /// </summary>
15 public readonly string ModUrl;
16 /// <summary>
17 /// Absolute web path to the React bundle if the mod has one, e.g. "/webmods/myMod/bundle.js"
18 /// </summary>
19 public readonly string ReactBundle;
20 /// <summary>
21 /// Absolute web path to a CSS if the mod has one, e.g. "/webmods/myMod/styling.css"
22 /// </summary>
23 public readonly string CssPath;
[426]24 public readonly bool IsWebMod;
[391]25
26 public WebMod (Web _parentWeb, Mod _parentMod, bool _useStaticCache) {
[426]27 ParentMod = _parentMod;
28
[402]29 string folder = $"{_parentMod.Path}/WebMod";
[426]30 IsWebMod = Directory.Exists (folder);
[391]31
[434]32 if (!IsWebMod) {
33 return;
34 }
[391]35
[463]36 ModUrl = $"{modsBaseUrl}{_parentMod.Name}/";
[391]37
[434]38 ReactBundle = $"{folder}/{reactBundleName}";
[463]39 ReactBundle = File.Exists (ReactBundle) ? $"{ModUrl}{reactBundleName}" : null;
[391]40
[434]41 CssPath = $"{folder}/{stylingFileName}";
[463]42 CssPath = File.Exists (CssPath) ? $"{ModUrl}{stylingFileName}" : null;
[434]43
[463]44 _parentWeb.RegisterPathHandler (ModUrl, new StaticHandler (
[434]45 folder,
46 _useStaticCache ? new SimpleCache () : new DirectAccess (),
47 false)
48 );
[391]49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.