Skip to content

Instantly share code, notes, and snippets.

@bernos
Created May 22, 2014 11:36
Show Gist options
  • Save bernos/5b22899bc121c4504bb6 to your computer and use it in GitHub Desktop.
Save bernos/5b22899bc121c4504bb6 to your computer and use it in GitHub Desktop.
Vagrant - Ubuntu precise 32 with mono 3.28 and nancy hosting examples
/**
* Uses Owin HttpListener to host the app. To get this working you'll need to
* install the following nuget packages
*
* install-package Microsoft.Owin.Hosting
* install-package Microsoft.Owin.Host.HttpListener
* install-package Nancy.Owin
*/
using Microsoft.Owin.Hosting;
using Owin;
using System;
using System.Linq;
using System.Threading;
namespace NancyOwin
{
class Program
{
static void Main(string[] args)
{
var uri = "http://localhost:8888";
using (WebApp.Start<Startup>(uri))
{
Console.WriteLine("Your application is running on " + uri);
Console.WriteLine("Press any key to close the host.");
//Under mono if you deamonize a process a Console.ReadLine with cause an EOF
//so we need to block another way
if (args.Any(s => s.Equals("-d", StringComparison.CurrentCultureIgnoreCase)))
{
Thread.Sleep(Timeout.Infinite);
}
else
{
Console.ReadKey();
}
}
}
}
class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseNancy();
}
}
}
/**
* Uses Nancy self hosting to host the app. To get this working you'll need to
* install the following nuget packages
*
* install-package Nancy.Hosting.Self
*/
using System;
using System.Linq;
using System.Threading;
using Nancy.Hosting.Self;
namespace NancyVagrant
{
class Program
{
static void Main(string[] args)
{
var uri =
new Uri("http://localhost:8888");
using (var host = new NancyHost(uri))
{
host.Start();
Console.WriteLine("Your application is running on " + uri);
Console.WriteLine("Press any [Enter] to close the host.");
//Under mono if you deamonize a process a Console.ReadLine with cause an EOF
//so we need to block another way
if (args.Any(s => s.Equals("-d", StringComparison.CurrentCultureIgnoreCase)))
{
Thread.Sleep(Timeout.Infinite);
}
else
{
Console.ReadKey();
}
}
}
}
}
#!/usr/bin/env bash
apt-get update
apt-get install -y git autoconf automake libtool g++ gettext make mono-complete curl unzip
mkdir ~/src
cd ~/src
wget http://download.mono-project.com/sources/mono/mono-3.2.8.tar.bz2
tar -xf mono-3.2.8.tar.bz2
cd mono-3.2.8
./autogen.sh --prefix=/usr/local
make
make install
mozroots --import --sync
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, :path => "vagrant-bootstrap.sh"
config.vm.network "forwarded_port", guest: 8888, host: 8888
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment