Changeset 426 for binary-improvements2/WebServer/src/Web.cs
- Timestamp:
- Apr 24, 2023, 2:40:34 PM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/Web.cs
r415 r426 16 16 public static event Action<Web> ServerInitialized; 17 17 18 private const int guestPermissionLevel = 2000;19 18 private const string indexPageUrl = "/app"; 20 19 … … 51 50 } 52 51 53 // TODO: Read from config54 bool useCacheForStatic = StringParsers.ParseBool ("false");55 56 string webfilesFolder = DetectWebserverFolder (_modInstancePath);57 58 52 ConnectionHandler = new ConnectionHandler (); 59 53 60 RegisterPathHandler ("/", new RewriteHandler ("/files/")); 61 62 // React virtual routing 63 RegisterPathHandler ("/app", new RewriteHandler ("/files/index.html", true)); 64 65 // Do mods relatively early as they should not be requested a lot, unlike the later registrations, especially for API and map tiles 66 RegisterWebMods (useCacheForStatic); 67 68 RegisterPathHandler ("/session/", new SessionHandler (ConnectionHandler)); 69 RegisterPathHandler ("/userstatus", new UserStatusHandler ()); 70 RegisterPathHandler ("/sse/", new SseHandler ()); 71 RegisterPathHandler ("/files/", new StaticHandler ( 72 webfilesFolder, 73 useCacheForStatic ? new SimpleCache () : new DirectAccess (), 74 false) 75 ); 76 RegisterPathHandler ("/itemicons/", new ItemIconHandler (true)); 77 RegisterPathHandler ("/api/", new ApiHandler ()); 54 RegisterDefaultHandlers (_modInstancePath); 78 55 79 56 // Allow other code to add their stuff … … 94 71 } 95 72 73 private void RegisterDefaultHandlers (string _modInstancePath) { 74 // TODO: Read from config 75 bool useCacheForStatic = StringParsers.ParseBool ("false"); 76 77 string webfilesFolder = DetectWebserverFolder (_modInstancePath); 78 79 RegisterPathHandler ("/", new RewriteHandler ("/files/")); 80 81 // React virtual routing 82 RegisterPathHandler ("/app", new RewriteHandler ("/files/index.html", true)); 83 84 // Do mods relatively early as they should not be requested a lot, unlike the later registrations, especially for API and map tiles 85 RegisterWebMods (useCacheForStatic); 86 87 RegisterPathHandler ("/session/", new SessionHandler (ConnectionHandler)); 88 RegisterPathHandler ("/userstatus", new UserStatusHandler ()); 89 RegisterPathHandler ("/sse/", new SseHandler ()); 90 RegisterPathHandler ("/files/", new StaticHandler ( 91 webfilesFolder, 92 useCacheForStatic ? new SimpleCache () : new DirectAccess (), 93 false) 94 ); 95 RegisterPathHandler ("/itemicons/", new ItemIconHandler (true)); 96 RegisterPathHandler ("/api/", new ApiHandler ()); 97 } 98 96 99 private static string DetectWebserverFolder (string _modInstancePath) { 97 100 string webserverFolder = $"{_modInstancePath}/webserver"; … … 127 130 foreach (Mod mod in ModManager.GetLoadedMods ()) { 128 131 try { 129 string webModPath = $"{mod.Path}/WebMod";130 if (!Directory.Exists (webModPath)) {131 continue;132 }133 134 132 try { 135 133 WebMod webMod = new WebMod (this, mod, _useStaticCache); … … 298 296 if (reqRemoteEndPoint == null) { 299 297 Log.Warning ("[Web] No RemoteEndPoint on web request"); 300 return guestPermissionLevel;298 return AdminWebModules.PermissionLevelGuest; 301 299 } 302 300 … … 316 314 if (!_req.Headers.TryGetValue ("X-SDTD-API-TOKENNAME", out string apiTokenName) || 317 315 !_req.Headers.TryGetValue ("X-SDTD-API-SECRET", out string apiTokenSecret)) { 318 return guestPermissionLevel;316 return AdminWebModules.PermissionLevelGuest; 319 317 } 320 318 … … 326 324 Log.Warning ($"[Web] Invalid Admintoken used from {reqRemoteEndPoint}"); 327 325 328 return guestPermissionLevel;326 return AdminWebModules.PermissionLevelGuest; 329 327 } 330 328 }
Note:
See TracChangeset
for help on using the changeset viewer.