https://github.com/gbih/fsharp-suave-dotliquid-starter
Simple hello-world starter for F# Suave and DotLiquid
https://github.com/gbih/fsharp-suave-dotliquid-starter
dotliquid fsharp suave
Last synced: 9 months ago
JSON representation
Simple hello-world starter for F# Suave and DotLiquid
- Host: GitHub
- URL: https://github.com/gbih/fsharp-suave-dotliquid-starter
- Owner: gbih
- Created: 2018-05-11T09:04:46.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-11T09:35:11.000Z (about 8 years ago)
- Last Synced: 2025-02-26T17:48:33.322Z (over 1 year ago)
- Topics: dotliquid, fsharp, suave
- Language: F#
- Size: 74.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Quick Setup
Clone this repo, then:
```sh
$ dotnet build
$ dotnet run
```
# Manual Setup
To build from scratch:
```sh
$ dotnet new console -lang F# -n MyApp
$ cd MyApp
$ dotnet add package Suave --version 2.4.0
$ dotnet add package DotLiquid --version 2.0.262
$ dotnet add package Suave.DotLiquid --version 2.4.0
```
Next, setup /templates and /assets folders:
```sh
$ mkdir {projectroot}/templates
$ mkdir {projectroot}/assets
$ cd templates
$ touch index.liquid
```
Create a sample index.liquid file:
```
{{model.title}}
```
Edit .fsproj file to allow Suave to serve all files inside /templates and /assets:
```
```
Sample Program.fs:
```fsharp
open Suave
open Suave.Filters
open Suave.Operators
open Suave.DotLiquid
open System.IO
open System.Reflection
let currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
let myHomeFolder = Path.Combine(Directory.GetCurrentDirectory(), "assets")
let initDotLiquid () =
let templatesDir = Path.Combine(currentPath, "views")
setTemplatesDir templatesDir
let cfg = {
defaultConfig with
bindings = [ HttpBinding.createSimple HTTP "127.0.0.1" 8080 ]
homeFolder = Some(myHomeFolder)
}
type Model = { title : string }
let o = { title = "Hello World" }
[]
let main argv =
printf "%s" myHomeFolder
initDotLiquid ()
setCSharpNamingConvention ()
let app =
choose [
pathRegex "(.*)\.(css|png|gif|js|ico)" >=> Files.browseHome
path "/" >=> choose [
GET >=> page "index.liquid" o ]
]
startWebServer cfg app
0
```
Build and run
```
$ dotnet build
$ dotnet run
```