source: binary-improvements/MapRendering/API.cs@ 456

Last change on this file since 456 was 455, checked in by alloc, 16 months ago

25_30_44

  • Got rid (mostly) of custom JSON serialization
  • Some code cleanup
File size: 1.4 KB
Line 
1using System;
2using System.IO;
3using JetBrains.Annotations;
4using Webserver.FileCache;
5using Webserver.UrlHandlers;
6
7namespace AllocsFixes.Web {
8 [UsedImplicitly]
9 public class API : IModApi {
10 private static Mod modInstance;
11
12 public void InitMod (Mod _modInstance) {
13 modInstance = _modInstance;
14
15 Webserver.Web.ServerInitialized += OnWebServerInitialized;
16 }
17
18 private static void OnWebServerInitialized (Webserver.Web _web) {
19 try {
20 const string legacyModUrl = "/legacymap";
21 const string legacyFilesFoldername = "webserver_legacy";
22 string legacyFilePath = $"{modInstance.Path}/{legacyFilesFoldername}";
23
24 if (!Directory.Exists (legacyFilePath)) {
25 Log.Out ($"Legacy webmod feature not started (folder \"{legacyFilesFoldername}\" not found in Allocs_WebAndMapRendering mod folder)");
26 return;
27 }
28
29 // TODO: Read from config
30 bool useStaticCache = false;
31
32 _web.RegisterPathHandler ($"{legacyModUrl}", new SimpleRedirectHandler ($"{legacyModUrl}/index.html"));
33 _web.RegisterPathHandler ($"{legacyModUrl}/", new StaticHandler (legacyFilePath, useStaticCache ? new SimpleCache () : new DirectAccess (), false));
34
35 int webPort = GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof(EnumGamePrefs.WebDashboardPort)));
36 Log.Out ($"Started legacy webmod feature on port {webPort}, local adress {legacyModUrl}");
37 } catch (Exception e) {
38 Log.Out ($"Error in Web.ctor: {e}");
39 }
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.