Skip to content

Instantly share code, notes, and snippets.

@dfinke
Created February 24, 2013 17:25
Show Gist options
  • Save dfinke/5024691 to your computer and use it in GitHub Desktop.
Save dfinke/5024691 to your computer and use it in GitHub Desktop.
pushd
md OWIN | out-null
cd OWIN
npm install express
npm install owin
Add-Type -OutputAssembly OwinHelloWorld.dll -TypeDefinition @"
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace OwinHelloWorld
{
public class Startup
{
public Task Invoke(IDictionary<string, object> env)
{
env["owin.ResponseStatusCode"] = 200;
((IDictionary<string, string[]>)env["owin.ResponseHeaders"]).Add(
"Content-Type", new string[] { "text/html" });
StreamWriter w = new StreamWriter((Stream)env["owin.ResponseBody"]);
w.Write("Hello, from C#. Time on server is " + DateTime.Now.ToString());
w.Flush();
return Task.FromResult<object>(null);
}
}
}
"@
$svr = @"
var owin = require('owin')
, express = require('express');
var app = express();
app.use(express.bodyParser());
app.all('/jazz', owin('OwinHelloWorld.dll'))
app.all('/rocknroll', function (req, res) {
res.send(200, 'Hello from JavaScript! Time on server ' + new Date());
});
app.listen(3000);
"@
$svr | Set-Content -Encoding Ascii -Path .\server.js
write-host -fore green @"
Try either:
http://localhost:3000/rocknroll
http://localhost:3000/jazz
"@
node server.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment