Created
May 20, 2014 12:11
-
-
Save deejaygraham/03b147c9719bddb7f09d to your computer and use it in GitHub Desktop.
Self-Hosted WebServer using Owin
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.Owin; | |
using Microsoft.Owin.FileSystems; | |
using Microsoft.Owin.Hosting; | |
using Microsoft.Owin.StaticFiles; | |
using Owin; | |
using System; | |
#if DEBUG | |
[assembly: OwinStartup(typeof(OwinTestApp.DebugStartup))] | |
#else | |
[assembly: OwinStartup(typeof(OwinTestApp.ProductionStartup))] | |
#endif | |
namespace OwinTestApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string url = (args.Length > 0) ? args[0] : "http://localhost:12345"; | |
using (WebApp.Start(url)) | |
{ | |
Console.WriteLine("Server listening at : " + url + ". Press a key to stop."); | |
Console.ReadKey(); | |
} | |
} | |
} | |
public class DebugStartup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
app.UseErrorPage(); | |
app.UseWelcomePage("/"); | |
} | |
} | |
public class ProductionStartup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var options = new FileServerOptions | |
{ | |
EnableDirectoryBrowsing = true, | |
FileSystem = new PhysicalFileSystem(".") | |
}; | |
app.UseFileServer(options); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment