Skip to content

Instantly share code, notes, and snippets.

@neoeinstein
Last active October 6, 2016 03:53
Show Gist options
  • Save neoeinstein/66c2c8ace158b3e701e206e172e91f8b to your computer and use it in GitHub Desktop.
Save neoeinstein/66c2c8ace158b3e701e206e172e91f8b to your computer and use it in GitHub Desktop.
Freya on .NET Core Proof of Concept
#!/bin/sh
dotnet restore
dotnet publish -c Release -r debian.8-x64
sudo docker build -t freya-poc .
FROM debian:jessie
EXPOSE 8080
RUN apt-get update && \
apt-get install -y libunwind8 libicu52 && \
rm -rf /var/lib/apt/lists/*
ADD bin/Release/netcoreapp1.3/debian.8-x64/publish/* /usr/local/lib/freya-svc/
ENTRYPOINT /usr/local/lib/freya-svc/freya-poc
open System
open Chiron
open Freya.Core
open Freya.Optics.Http
open Freya.Types.Http
open Freya.Machines.Http
open Freya.Routers.Uri.Template
let name = freya {
let! name = Freya.Optic.get (Route.atom_ "name")
match name with
| Some name -> return name
| None -> return "World"
}
let hello = freya {
let! name = name
return Represent.text (sprintf "Hello %s!" name)
}
let machine = freyaMachine {
handleOk hello
}
let router = freyaRouter {
resource "/hello{/name}" machine
}
open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
type Startup() =
member __.Configure (app:IApplicationBuilder) : unit =
let freyaOwin = OwinMidFunc.ofFreya (UriTemplateRouter.Freya router)
app.UseOwin (fun p -> p.Invoke(freyaOwin)) |> ignore
[<EntryPoint>]
let main argv =
printfn "Hello World!"
printfn "%A" argv
printfn "%A" (Json.parse """{"Hello":"Face","Test":true}""")
printfn "%A" (Json.format (Json.Object Map.empty))
let _ = WebHostBuilder().UseUrls([|"http://*:8080"|]).UseKestrel().UseStartup<Startup>().Build().Run()
0 // return an integer exit code
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true,
"optimize": true,
"compilerName": "fsc",
"compile": {
"includeFiles": [
"FreyaProgram.fs"
]
}
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true,
"System.GC.Concurrent": true
}
},
"dependencies": {
"Microsoft.FSharp.Core.netcore": "1.0.0-alpha-160509",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"FParsec": "1.0.2",
"Chiron": "6.2.0",
"Freya": "3.0.0-rc01",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Owin": "1.0.0"
},
"tools": {
"dotnet-compile-fsc": {
"version": "1.0.0-preview2-*",
"imports": [
"dnxcore50",
"portable-net45+win81",
"netstandard1.3"
]
}
},
"frameworks": {
"netcoreapp1.3": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0"
}
},
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8",
"net452",
"dnxcore50"
]
}
},
"runtimes": {
"debian.8-x64": {},
"ubuntu.16.04-x64": {}
}
}
@khalidabuhakmeh
Copy link

khalidabuhakmeh commented Sep 11, 2016

For those looking to run this one MacOS you will need to change the runtimes section to this:

  "runtimes": {
    "osx.10.11-x64": {}
  }

Also you don't need to run in Docker at that point :)

@danieljsummers
Copy link

Thanks for this - it helped get me a Freya example to build on .NET core. I hopefully will, when everything is done, have a great example of the progression from ASP.NET MVC -> Nancy C# -> Nancy F# -> Freya that will help OO devs understand the functional way - myself included! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment