Created
November 7, 2016 15:59
-
-
Save igloo15/9cd99b48b17d3c8c962b92d41c77eb39 to your computer and use it in GitHub Desktop.
Server class for kestrel web server
This file contains hidden or 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.Hosting; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace WebServer.Main | |
{ | |
public class Server | |
{ | |
private WebHostBuilder _serverBuilder = null; | |
private IWebHost _server = null; | |
public Server(string path, string port = "1515", string webroot = "") | |
{ | |
if (webroot == null) | |
throw new ArgumentNullException("webroot"); | |
if (String.IsNullOrEmpty(path)) | |
path = Directory.GetCurrentDirectory(); | |
if (String.IsNullOrEmpty(port)) | |
port = "5000"; | |
_serverBuilder = new WebHostBuilder(); | |
_server = _serverBuilder | |
.UseKestrel() | |
.UseContentRoot(path) | |
.UseWebRoot(webroot) | |
.UseStartup<Startup>() | |
.UseUrls($"http://localhost:{port}") | |
.Build(); | |
} | |
public void Start() | |
{ | |
_server.Run(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment