Rev | Line | |
---|
[391] | 1 | using System.IO;
|
---|
[402] | 2 | using Webserver.FileCache;
|
---|
[391] | 3 | using Webserver.UrlHandlers;
|
---|
| 4 |
|
---|
| 5 | namespace 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";
|
---|
[426] | 14 | public readonly bool IsWebMod;
|
---|
[391] | 15 |
|
---|
| 16 | public WebMod (Web _parentWeb, Mod _parentMod, bool _useStaticCache) {
|
---|
[426] | 17 | ParentMod = _parentMod;
|
---|
| 18 |
|
---|
[402] | 19 | string folder = $"{_parentMod.Path}/WebMod";
|
---|
[426] | 20 | IsWebMod = Directory.Exists (folder);
|
---|
[391] | 21 |
|
---|
[434] | 22 | if (!IsWebMod) {
|
---|
| 23 | return;
|
---|
| 24 | }
|
---|
[391] | 25 |
|
---|
[434] | 26 | string urlWebModBase = $"{modsBaseUrl}{_parentMod.FolderName}/";
|
---|
[391] | 27 |
|
---|
[434] | 28 | ReactBundle = $"{folder}/{reactBundleName}";
|
---|
| 29 | ReactBundle = File.Exists (ReactBundle) ? $"{urlWebModBase}{reactBundleName}" : null;
|
---|
[391] | 30 |
|
---|
[434] | 31 | CssPath = $"{folder}/{stylingFileName}";
|
---|
| 32 | CssPath = File.Exists (CssPath) ? $"{urlWebModBase}{stylingFileName}" : null;
|
---|
| 33 |
|
---|
| 34 | _parentWeb.RegisterPathHandler (urlWebModBase, new StaticHandler (
|
---|
| 35 | folder,
|
---|
| 36 | _useStaticCache ? new SimpleCache () : new DirectAccess (),
|
---|
| 37 | false)
|
---|
| 38 | );
|
---|
[391] | 39 | }
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.