Skip to content

Instantly share code, notes, and snippets.

@deejaygraham
Created May 20, 2014 12:11
Show Gist options
  • Save deejaygraham/03b147c9719bddb7f09d to your computer and use it in GitHub Desktop.
Save deejaygraham/03b147c9719bddb7f09d to your computer and use it in GitHub Desktop.
Self-Hosted WebServer using Owin
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