mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 13:33:13 +00:00
aaaaa
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user