Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Implement node.js express handlers and connect middleware in .NET using OWIN
JavaScript C#
branch: master

This branch is 24 commits ahead of tjanczuk:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
samples
src/Owin.Connect
test
.gitignore
LICENSE.txt
README.md
package.json

README.md

The project has been renamed connect-owin and moved to https://github.com/bbaia/connect-owin

edge-connect

Implement node.js express handlers and connect middleware in .NET using OWIN

The lay of the land

This module has a package.json dependency on the edge@0.7.10 module which provides basic .NET to node.js interop mechanisms.

The src\Owin.Connect directory contains a C# library project that implements an OWIN HTTP server. The server implements two functions: Initialize and Handle. The Initialize is responsible for loading and configuring an OWIN .NET application. This is where all the patterns of OWIN OM would need to be implemented. The Handle is responsible for processing a single HTTP request using one of the previously loaded OWIN .NET applications, normalized to Func<IDictionary<string,object>,Task> form. Both Initialize and Handle are exposed to node.js using the fundational capabilities of edge. The lib\owin-connect.js calls these functions from node.js.

The lib\owin-connect.js exports 2 functions that are a factory of connect middleware. The invoke function supports the application delegate (or AppFunc) Func<IDictionary<string,object>,Task> defined by the OWIN specification. The configuration function supports Microsoft IAppBuilder pipeline defined in Owin.dll. Both functions accept the same arguments as the edge.func function (along with other optional parameters) to allow OWIN .NET application code to be pre-compiled or specified as C#.

Building

The Owin.Connect library needs to be built first. Once we arrive in a stable place, a binary will be checked into git to make consuming edge-connect easier.

From a VS 2012 command prompt, go to the root of the project and

msbuild src\Owin.Connect\Owin.Connect.sln
set OWIN_CONNECT_NATIVE=C:\projects\edge-connect\src\Owin.Connect\bin\Debug\Owin.Connect.dll

The OWIN_CONNECT_NATIVE must be set to the location of the built Owin.Connect.dll. The owin-connect.js will use that location if specified. This is helpful during development and required until a stable binary is checked into the repo.

Running the sample

You need Windows, node.js 0.8.x (tested with 0.8.19), and .NET 4.5 along with VS 2012 toolset for building.

Assuming the project was git-cloned and built, run this from the VS 2012 command prompt from the root of the project:

npm install
cd samples\hello
npm install express
build.bat
node server.js

The go to http://localhost:3000/node. This should display a message from an express handler in node.js.

If you go to http://localhost:3000/net/csx (uses embedded C# code) or http://localhost:3000/net/dll (uses pre-compiled CLR assembly), you should see a similar message from the .NET OWIN application in Owin.Samples.dll plugged in as a handler to the express pipeline.

Running tests

You'll need to install mocha globally by running:

npm install -g mocha

Assuming the project was git-cloned and built, run this from the VS 2012 command prompt from the root of the project:

npm install
test\build.bat
mocha
Something went wrong with that request. Please try again.