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

Last change on this file since 465 was 463, checked in by alloc, 15 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
Line 
1using System.IO;
2using Webserver.FileCache;
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;
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;
24 public readonly bool IsWebMod;
25
26 public WebMod (Web _parentWeb, Mod _parentMod, bool _useStaticCache) {
27 ParentMod = _parentMod;
28
29 string folder = $"{_parentMod.Path}/WebMod";
30 IsWebMod = Directory.Exists (folder);
31
32 if (!IsWebMod) {
33 return;
34 }
35
36 ModUrl = $"{modsBaseUrl}{_parentMod.Name}/";
37
38 ReactBundle = $"{folder}/{reactBundleName}";
39 ReactBundle = File.Exists (ReactBundle) ? $"{ModUrl}{reactBundleName}" : null;
40
41 CssPath = $"{folder}/{stylingFileName}";
42 CssPath = File.Exists (CssPath) ? $"{ModUrl}{stylingFileName}" : null;
43
44 _parentWeb.RegisterPathHandler (ModUrl, new StaticHandler (
45 folder,
46 _useStaticCache ? new SimpleCache () : new DirectAccess (),
47 false)
48 );
49 }
50 }
51}
Note: See TracBrowser for help on using the repository browser.