source: binary-improvements2/WebServer/src/WebMod.cs@ 402

Last change on this file since 402 was 402, checked in by alloc, 22 months ago
  • Major refactoring
  • Using Utf8Json for (de)serialization
  • Moving APIs to REST
  • Removing dependencies from WebServer and MapRenderer to ServerFixes
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 public readonly string ReactBundle; // Absolute web path to the React bundle if the mod has one, e.g. "/webmods/myMod/bundle.js"
13 public readonly string CssPath; // Absolute web path to a CSS if the mod has one, e.g. "/webmods/myMod/styling.css";
14
15 public WebMod (Web _parentWeb, Mod _parentMod, bool _useStaticCache) {
16 string folder = $"{_parentMod.Path}/WebMod";
17 if (!Directory.Exists (folder)) {
18 throw new InvalidDataException("No WebMod folder in mod");
19 }
20
21 string urlWebModBase = $"{modsBaseUrl}{_parentMod.FolderName}/";
22
23 ReactBundle = $"{folder}/{reactBundleName}";
24 ReactBundle = File.Exists (ReactBundle) ? $"{urlWebModBase}{reactBundleName}" : null;
25
26 CssPath = $"{folder}/{stylingFileName}";
27 CssPath = File.Exists (CssPath) ? $"{urlWebModBase}{stylingFileName}" : null;
28
29 if (ReactBundle == null && CssPath == null) {
30 throw new InvalidDataException($"WebMod folder has neither a {reactBundleName} nor a {stylingFileName}");
31 }
32
33 ParentMod = _parentMod;
34
35 _parentWeb.RegisterPathHandler (urlWebModBase, new StaticHandler (
36 folder,
37 _useStaticCache ? new SimpleCache () : new DirectAccess (),
38 false)
39 );
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.