Created
January 30, 2020 22:31
-
-
Save gamemachine/d7a91fd7072014c0da9cfe5da756b709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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