├── .gitignore ├── .paket ├── paket.bootstrapper.exe └── paket.targets ├── LICENSE ├── NancyFs.sln ├── README.md ├── build.bat ├── build.fsx ├── paket.dependencies ├── paket.lock └── src └── NancyFs ├── Bootstrapper.fs ├── Content ├── Css │ └── Styles.css ├── Img │ └── Logo.png └── Js │ └── Script.js ├── Models └── Models.fs ├── Modules ├── Modules.fs ├── Nancy.fs └── Routes.fs ├── NancyFs.fsproj ├── Views ├── About.cshtml ├── Home.cshtml ├── Shared │ └── Layout.cshtml └── Welcome.cshtml ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── paket.references └── robots.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | build/ 5 | 6 | # mstest test results 7 | TestResults 8 | 9 | ## Ignore Visual Studio temporary files, build results, and 10 | ## files generated by popular Visual Studio add-ons. 11 | 12 | # User-specific files 13 | *.suo 14 | *.user 15 | *.sln.docstates 16 | *.sln.DotSettings 17 | 18 | # Build results 19 | [Dd]ebug/ 20 | [Rr]elease/ 21 | x64/ 22 | *_i.c 23 | *_p.c 24 | *.ilk 25 | *.meta 26 | *.obj 27 | *.pch 28 | *.pdb 29 | *.pgc 30 | *.pgd 31 | *.rsp 32 | *.sbr 33 | *.tlb 34 | *.tli 35 | *.tlh 36 | *.tmp 37 | *.log 38 | *.vspscc 39 | *.vssscc 40 | .builds 41 | 42 | # Visual C++ cache files 43 | ipch/ 44 | *.aps 45 | *.ncb 46 | *.opensdf 47 | *.sdf 48 | 49 | # Visual Studio profiler 50 | *.psess 51 | *.vsp 52 | *.vspx 53 | 54 | # Guidance Automation Toolkit 55 | *.gpState 56 | 57 | # ReSharper is a .NET coding add-in 58 | _ReSharper* 59 | 60 | # NCrunch 61 | *.ncrunch* 62 | .*crunch*.local.xml 63 | ncrunchTemp* 64 | *_ncrunch* 65 | 66 | # Installshield output folder 67 | [Ee]xpress 68 | 69 | # DocProject is a documentation generator add-in 70 | DocProject/buildhelp/ 71 | DocProject/Help/*.HxT 72 | DocProject/Help/*.HxC 73 | DocProject/Help/*.hhc 74 | DocProject/Help/*.hhk 75 | DocProject/Help/*.hhp 76 | DocProject/Help/Html2 77 | DocProject/Help/html 78 | 79 | # Click-Once directory 80 | publish 81 | 82 | # Publish Web Output 83 | *.Publish.xml 84 | 85 | # NuGet Packages Directory 86 | packages 87 | 88 | # Windows Azure Build Output 89 | csx 90 | *.build.csdef 91 | 92 | # Windows Store app package directory 93 | AppPackages/ 94 | 95 | # Others 96 | [Bb]in 97 | [Oo]bj 98 | sql 99 | TestResults 100 | [Tt]est[Rr]esult* 101 | *.Cache 102 | ClientBin 103 | [Ss]tyle[Cc]op.* 104 | ~$* 105 | *.dbmdl 106 | Generated_Code #added for RIA/Silverlight projects 107 | 108 | # Backup & report files from converting an old project file to a newer 109 | # Visual Studio version. Backup files are not needed, because we have git ;-) 110 | _UpgradeReport_Files/ 111 | Backup*/ 112 | UpgradeLog*.XML 113 | 114 | src/UITests/results.xml 115 | 116 | paket-files -------------------------------------------------------------------------------- /.paket/paket.bootstrapper.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinyBlueRobots/NancyFs/043a751a9ae2148eb45ca5a889b507c35a1df905/.paket/paket.bootstrapper.exe -------------------------------------------------------------------------------- /.paket/paket.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | true 8 | $(MSBuildThisFileDirectory) 9 | $(MSBuildThisFileDirectory)..\ 10 | 11 | 12 | 13 | $(PaketToolsPath)paket.exe 14 | $(PaketToolsPath)paket.bootstrapper.exe 15 | "$(PaketExePath)" 16 | mono --runtime=v4.0.30319 $(PaketExePath) 17 | "$(PaketBootStrapperExePath)" 18 | mono --runtime=v4.0.30319 $(PaketBootStrapperExePath) 19 | 20 | $(MSBuildProjectDirectory)\paket.references 21 | $(MSBuildProjectFullPath).paket.references 22 | $(PaketCommand) restore --references-files "$(PaketReferences)" 23 | $(PaketBootStrapperCommand) 24 | 25 | RestorePackages; $(BuildDependsOn); 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jon Canning 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /NancyFs.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{1EDD1986-C89C-4987-992B-D3DB85D1BEC3}" 7 | ProjectSection(SolutionItems) = preProject 8 | paket.dependencies = paket.dependencies 9 | EndProjectSection 10 | EndProject 11 | Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "NancyFs", "src\NancyFs\NancyFs.fsproj", "{B5D510EF-2627-4606-9BC4-0ED8988EEA79}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {B5D510EF-2627-4606-9BC4-0ED8988EEA79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {B5D510EF-2627-4606-9BC4-0ED8988EEA79}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {B5D510EF-2627-4606-9BC4-0ED8988EEA79}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {B5D510EF-2627-4606-9BC4-0ED8988EEA79}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NancyFs 2 | == 3 | A template project for using NancyFx with F#, plus some functional helpers to make it smoother 4 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cls 3 | .paket\paket.bootstrapper 4 | .paket\paket restore 5 | packages\FAKE\tools\Fake %1 -------------------------------------------------------------------------------- /build.fsx: -------------------------------------------------------------------------------- 1 | #r "packages/FAKE/tools/FakeLib.dll" 2 | let solutionFile = "NancyFs.sln" 3 | open Fake 4 | Target "Default" (fun _ -> 5 | !!"src/**/bin/Release/" |> CleanDirs 6 | !!solutionFile 7 | |> MSBuildRelease "" "Build" 8 | |> ignore) 9 | 10 | RunTargetOrDefault "Default" -------------------------------------------------------------------------------- /paket.dependencies: -------------------------------------------------------------------------------- 1 | source https://nuget.org/api/v2 2 | 3 | nuget Nancy.Hosting.Aspnet 4 | nuget Nancy.Viewengines.Razor 5 | nuget FSharp.Management 6 | nuget fake 7 | nuget MSBuild.Microsoft.VisualStudio.Web.targets 8 | -------------------------------------------------------------------------------- /paket.lock: -------------------------------------------------------------------------------- 1 | NUGET 2 | remote: https://nuget.org/api/v2 3 | specs: 4 | FAKE (3.23.0) 5 | FSharp.Management (0.2.0) 6 | Microsoft.AspNet.Razor (3.2.2) 7 | Nancy (1.1) 8 | Nancy.Hosting.Aspnet (1.1) 9 | Nancy (>= 1.1) 10 | Nancy.Viewengines.Razor (1.1) 11 | Microsoft.AspNet.Razor 12 | Microsoft.AspNet.Razor (>= 2.0.30506) - framework: >= net40 13 | Nancy (>= 1.1) 14 | -------------------------------------------------------------------------------- /src/NancyFs/Bootstrapper.fs: -------------------------------------------------------------------------------- 1 | module Bootstrapper 2 | 3 | open Nancy 4 | 5 | type Bootstrapper() = 6 | inherit DefaultNancyBootstrapper() -------------------------------------------------------------------------------- /src/NancyFs/Content/Css/Styles.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | } 4 | 5 | html, body { 6 | height: 100%; 7 | } 8 | 9 | .wrapper { 10 | min-height: 100%; 11 | height: auto !important; 12 | height: 100%; 13 | margin: 0 auto -4em; 14 | } 15 | 16 | .footer, .push { 17 | height: 4em; 18 | } 19 | 20 | header, footer { 21 | background-color: black; 22 | } 23 | -------------------------------------------------------------------------------- /src/NancyFs/Content/Img/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TinyBlueRobots/NancyFs/043a751a9ae2148eb45ca5a889b507c35a1df905/src/NancyFs/Content/Img/Logo.png -------------------------------------------------------------------------------- /src/NancyFs/Content/Js/Script.js: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/NancyFs/Models/Models.fs: -------------------------------------------------------------------------------- 1 | [] 2 | module Models 3 | 4 | [] 5 | type NameModel = 6 | {Name : string} 7 | -------------------------------------------------------------------------------- /src/NancyFs/Modules/Modules.fs: -------------------------------------------------------------------------------- 1 | [] 2 | module Modules 3 | 4 | module Home = 5 | let get() = View(Views.``Home.cshtml``, None) 6 | let post nameModel = View(Views.``Welcome.cshtml``, Some nameModel) 7 | 8 | module About = 9 | let get (name : string option) = 10 | View(Views.``About.cshtml``, name) 11 | 12 | module StaticFile = 13 | let get parameters = 14 | match parameters?file with 15 | | Some file -> File file 16 | | None -> NotFound 17 | 18 | module Redirect = 19 | let get redirect = 20 | match redirect with 21 | | Some true -> PermanentRedirect "/about" 22 | | _ -> View(Views.``Home.cshtml``, None) 23 | -------------------------------------------------------------------------------- /src/NancyFs/Modules/Nancy.fs: -------------------------------------------------------------------------------- 1 | [] 2 | module NancyFs 3 | 4 | open FSharp.Management 5 | open Nancy 6 | open Nancy.Responses 7 | open System 8 | 9 | let (?) (p : obj) prop = 10 | let ddv = (p :?> DynamicDictionary).[prop] :?> DynamicDictionaryValue 11 | match ddv.HasValue with 12 | | false -> None 13 | | _ -> ddv.TryParse<'a>() |> Some 14 | 15 | type Views = RelativePath< ".\\Views", watch=true > 16 | 17 | type Response<'a> = 18 | | View of string * 'a option 19 | | File of string 20 | | NotFound 21 | | PermanentRedirect of string 22 | | Json of 'a 23 | 24 | type HTTPMethod = 25 | | DELETE 26 | | GET 27 | | OPTIONS 28 | | PATCH 29 | | POST 30 | | PUT 31 | 32 | let (|ViewName|) (viewName : string) = viewName.Replace("\\", "/") 33 | 34 | type NancyFsModule() = 35 | inherit NancyModule() 36 | 37 | member private this.Nancify response = 38 | match response with 39 | | View(ViewName viewName, None) -> this.View.[viewName] |> box 40 | | View(ViewName viewName, Some model) -> this.View.[viewName, model] |> box 41 | | File path -> this.Response.AsFile path |> box 42 | | NotFound -> HttpStatusCode.NotFound |> box 43 | | PermanentRedirect path -> this.Response.AsRedirect(path, RedirectResponse.RedirectType.Permanent) |> box 44 | | Json o -> this.Response.AsJson o |> box 45 | 46 | member this.CreateRoute httpMethod route f = 47 | let f = Func(fun p -> f p |> this.Nancify) 48 | match httpMethod with 49 | | DELETE -> base.Delete.[route] <- f 50 | | GET -> base.Get.[route] <- f 51 | | OPTIONS -> base.Options.[route] <- f 52 | | PATCH -> base.Patch.[route] <- f 53 | | POST -> base.Post.[route] <- f 54 | | PUT -> base.Put.[route] <- f 55 | 56 | member this.CreateAsyncRoute httpMethod route f = 57 | let f = 58 | fun p c -> 59 | let computation = async { let! response = f p c 60 | return response |> this.Nancify } 61 | Async.StartAsTask(computation, cancellationToken = c) 62 | match httpMethod with 63 | | DELETE -> base.Delete.[route, true] <- f 64 | | GET -> base.Get.[route, true] <- f 65 | | OPTIONS -> base.Options.[route, true] <- f 66 | | PATCH -> base.Patch.[route, true] <- f 67 | | POST -> base.Post.[route, true] <- f 68 | | PUT -> base.Put.[route, true] <- f 69 | -------------------------------------------------------------------------------- /src/NancyFs/Modules/Routes.fs: -------------------------------------------------------------------------------- 1 | module Routes 2 | 3 | open Nancy.ModelBinding 4 | 5 | type Routes() as this = 6 | inherit NancyFsModule() 7 | do 8 | (fun _ -> Home.get()) |> this.CreateRoute GET "/" 9 | (fun _ -> this.Bind() |> Home.post) |> this.CreateRoute POST "/" 10 | (fun _ -> this.Request.Query?name |> About.get) |> this.CreateRoute GET "/about" 11 | StaticFile.get |> this.CreateRoute GET "/{file}" 12 | (fun p -> p?redirect |> Redirect.get) |> this.CreateRoute GET "/redirect/{redirect}" 13 | -------------------------------------------------------------------------------- /src/NancyFs/NancyFs.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | 2.0 9 | {b5d510ef-2627-4606-9bc4-0ed8988eea79} 10 | {349c5851-65df-11da-9384-00065b846f21};{F2A71F9B-5D33-465A-A702-920D77279786} 11 | Library 12 | true 13 | NancyFs 14 | NancyFs 15 | v4.5.1 16 | 17 | 18 | EmptyAspNetHostWithRazor 19 | true 20 | 21 | 22 | 23 | 24 | 4.3.1.0 25 | 11 26 | 27 | 28 | true 29 | full 30 | false 31 | false 32 | bin\ 33 | DEBUG;TRACE 34 | 4 35 | 36 | 37 | pdbonly 38 | true 39 | true 40 | bin\ 41 | TRACE 42 | 4 43 | 44 | 45 | 46 | 47 | $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets 48 | 49 | 50 | 51 | 52 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | True 62 | True 63 | 11516 64 | / 65 | http://localhost:11516/ 66 | False 67 | False 68 | 69 | 70 | False 71 | 72 | 73 | 74 | 75 | 76 | 77 | CurrentPage 78 | True 79 | False 80 | False 81 | False 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | False 91 | True 92 | 93 | 94 | 95 | 96 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | Web.config 119 | 120 | 121 | Web.config 122 | 123 | 124 | 125 | 126 | 127 | 128 | True 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | ..\..\packages\Microsoft.AspNet.Razor\lib\net45\System.Web.Razor.dll 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | ..\..\packages\FSharp.Management\lib\net40\FSharp.Management.PowerShell.ExternalRuntime.exe 151 | True 152 | True 153 | 154 | 155 | ..\..\packages\FSharp.Management\lib\net40\FSharp.Management.PowerShell.dll 156 | True 157 | True 158 | 159 | 160 | ..\..\packages\FSharp.Management\lib\net40\FSharp.Management.WMI.DesignTime.dll 161 | True 162 | True 163 | 164 | 165 | ..\..\packages\FSharp.Management\lib\net40\FSharp.Management.WMI.dll 166 | True 167 | True 168 | 169 | 170 | ..\..\packages\FSharp.Management\lib\net40\FSharp.Management.dll 171 | True 172 | True 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | ..\..\packages\Nancy\lib\net40\Nancy.dll 182 | True 183 | True 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | ..\..\packages\Nancy.Hosting.Aspnet\lib\net40\Nancy.Hosting.Aspnet.dll 193 | True 194 | True 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | ..\..\packages\Nancy.Viewengines.Razor\lib\net40\Nancy.ViewEngines.Razor.dll 204 | True 205 | True 206 | 207 | 208 | 209 | 210 | 211 | -------------------------------------------------------------------------------- /src/NancyFs/Views/About.cshtml: -------------------------------------------------------------------------------- 1 | @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase 2 | 3 | @{ 4 | Layout = "Shared/Layout"; 5 | ViewBag.Title = "About"; 6 | ViewBag.Description = "All about us"; 7 | } 8 | 9 |

About

10 | 11 | We're great 12 | @if (Model != null) 13 | { 14 | 15 | and so are you @Model 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/NancyFs/Views/Home.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "Shared/Layout"; 3 | ViewBag.Title = "Home Page"; 4 | ViewBag.Description = "All about home"; 5 | } 6 | 7 |

Please tell me your name

8 | 9 |
10 | 11 | 12 |
-------------------------------------------------------------------------------- /src/NancyFs/Views/Shared/Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | NancyFs | @ViewBag.Title 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | @RenderBody() 30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | 40 |
41 | 42 | 43 | 44 | 45 | @RenderSection("Scripts", false) 46 | 47 | -------------------------------------------------------------------------------- /src/NancyFs/Views/Welcome.cshtml: -------------------------------------------------------------------------------- 1 | @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase 2 | 3 | @{ 4 | Layout = "Shared/Layout"; 5 | ViewBag.Title = "Welcome"; 6 | ViewBag.Description = "Welcome page"; 7 | } 8 | 9 |

Welcome @Model.Name

10 |

11 | Thanks for coming 12 |

13 |

14 | Found out about us 15 |

-------------------------------------------------------------------------------- /src/NancyFs/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /src/NancyFs/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /src/NancyFs/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/NancyFs/paket.references: -------------------------------------------------------------------------------- 1 | Nancy.Hosting.Aspnet 2 | Nancy.Viewengines.Razor 3 | FSharp.Management 4 | MSBuild.Microsoft.VisualStudio.Web.targets 5 | -------------------------------------------------------------------------------- /src/NancyFs/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | allow: * --------------------------------------------------------------------------------