Skip to content

Instantly share code, notes, and snippets.

@gamemachine
Created January 30, 2020 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamemachine/d7a91fd7072014c0da9cfe5da756b709 to your computer and use it in GitHub Desktop.
Save gamemachine/d7a91fd7072014c0da9cfe5da756b709 to your computer and use it in GitHub Desktop.
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