Funscript.Owin

FunScript compilation middleware for OWIN

FunScript and OWIN

FunScript middleware

Get Started

New F# project (Console app). Set target framework to .NET 4.5.

NuGet

Install the following packages (Nancy.Owin or the HttpListener Owin implementation can be replaced by whatever you like)

Install-Package FunScript.Owin
Install-Package Microsoft.Owin.Host.HttpListener -Pre
Install-Package Microsoft.Owin.Hosting -pre
Install-Package Nancy.Owin

Example

A simple example.

canvas() is exported into "/scripts/canvas.js"

It uses Nancy to host the static files. (HTML). Put the html in the /web/ folder and access http://localhost:8080/web/Index.html (for example). Be sure to include "/script/canvas.js".


open System.Reflection

open Owin

open Microsoft.Owin.Hosting

open FunScript
open FunScript.TypeScript
open FunScript.Owin

open Nancy
open Nancy.Conventions


[<FunScript.JS>]
module JS = 
    type ts = Api<"../Typings/lib.d.ts">

    [<Export("canvas.js")>]
    let canvas() = 
        let canvas = unbox<ts.HTMLCanvasElement>(ts.document.getElementById("canvas"))
        canvas.width <- 1000.
        canvas.height <- 800.
        let ctx = canvas.getContext("2d")
        ctx.fillStyle <- "rgb(200,0,0)"
        ctx.fillRect (10., 10., 55., 50.);
        ctx.fillStyle <- "rgba(0, 0, 200, 0.5)"
        ctx.fillRect (30., 30., 55., 50.)


module App =
    type ApplicationBootstrapper() =
        inherit DefaultNancyBootstrapper()
        override this.ConfigureConventions(nancyConventions:NancyConventions) =
            nancyConventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("web", @"web"))
            base.ConfigureConventions(nancyConventions);

    type Startup() =
        member public this.Configuration(app:IAppBuilder) =
            app.UseFunScript("scripts", Assembly.GetExecutingAssembly(), Interop.Components.all) |> ignore
            app.UseNancy(new ApplicationBootstrapper()) |> ignore

    [<EntryPoint>]
    let main argv = 
        //end point
        let url = "http://localhost:8080"
        //web app
        use a = WebApplication.Start<Startup>(url)

        System.Console.WriteLine("Server running at {0}",url)      
        System.Console.ReadLine() |> ignore
        0

For a full example check: https://github.com/Fristi/FunScript.Owin/tree/master/FunScript.Owin.Example