2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 13:33:13 +00:00
This commit is contained in:
2024-06-09 20:42:25 +03:00
parent 62617f2c30
commit 08410de9c3
10 changed files with 811 additions and 7 deletions

View File

@ -1,10 +1,16 @@

using Esiur.Examples.StandaloneWebServerDemo;
using Esiur.Net.HTTP;
using Esiur.Net.IIP;
using Esiur.Resource;
using Esiur.Stores;
using Microsoft.AspNetCore.StaticFiles;
internal class Program
{
static FileExtensionContentTypeProvider MIMEProvider = new FileExtensionContentTypeProvider();
private static async Task Main(string[] args)
{
// Create a store to keep objects.
@ -12,7 +18,34 @@ internal class Program
// Create a distibuted server
var esiurServer = await Warehouse.Put("sys/server", new DistributedServer());
// Add your object to the store
var service = await Warehouse.Put("sys/demo", new EsiurGreeter());
var service = await Warehouse.Put("sys/demo", new Demo());
var http = await Warehouse.Put<HTTPServer>("sys/http", new HTTPServer() { Port = 8080 });
http.MapGet("{url}", (string url, HTTPConnection sender) =>
{
var fn = "Web/" + (sender.Request.Filename == "/" ? "/index.html" : sender.Request.Filename);
if (File.Exists(fn))
{
string contentType;
if (!MIMEProvider.TryGetContentType(fn, out contentType))
contentType = "application/octet-stream";
sender.Response.Headers["Content-Type"] = contentType;
sender.SendFile(fn).Wait(20000);
}
else
{
sender.Response.Number = Esiur.Net.Packets.HTTPResponsePacket.ResponseCode.NotFound;
sender.Send("`" + fn + "` Not Found");
sender.Close();
}
});
// Start your server