using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.Logging; | |
namespace Server.Http | |
{ | |
public class HttpServer | |
{ | |
private static IWebHost Host; | |
public static void Start() | |
{ | |
string ip = "127.0.0.1"; | |
string url = string.Format("http://{0}:9696/", ip); | |
Host = new WebHostBuilder() | |
.UseKestrel() | |
.UseUrls(url) | |
.ConfigureLogging(builder => ConfigureLogging(builder)) | |
.Configure(app => Configure(app)) | |
.Build(); | |
Host.Start(); | |
} | |
private static void ConfigureLogging(ILoggingBuilder builder) | |
{ | |
builder.AddConsole(); | |
builder.SetMinimumLevel(LogLevel.Information); | |
} | |
private static void Configure(IApplicationBuilder app) | |
{ | |
app.Map("/hello", HelloHandler); | |
} | |
private static void HelloHandler(IApplicationBuilder app) | |
{ | |
app.Run(async context => | |
{ | |
context.Response.ContentType = context.Request.ContentType; | |
await context.Response.WriteAsync("Hello"); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment