mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-07 12:16:04 +00:00
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WelsonJS.Launcher.ResourceTools
|
|
{
|
|
public class Config : IResourceTool
|
|
{
|
|
private ResourceServer Server;
|
|
private const string Prefix = "config/";
|
|
|
|
public Config(ResourceServer server)
|
|
{
|
|
Server = server;
|
|
}
|
|
|
|
public bool CanHandle(string path)
|
|
{
|
|
return path.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public async Task HandleAsync(HttpListenerContext context, string path)
|
|
{
|
|
await Task.Delay(0);
|
|
|
|
string configName = path.Substring(Prefix.Length);
|
|
|
|
try
|
|
{
|
|
string configValue = Program.GetAppConfig(configName);
|
|
Server.ServeResource(context, configValue, "text/plain");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Server.ServeResource(context, $"<error>Failed to process Config request. {ex.Message}</error>", "application/xml", 500);
|
|
}
|
|
}
|
|
}
|
|
}
|