Instantly share code, notes, and snippets.

Embed
What would you like to do?
namespace runWebsite
open WebSharper
open WebSharper.Sitelets
open WebSharper.UI
open WebSharper.UI.Server
type EndPoint =
| [<EndPoint "/">] Home
| [<EndPoint "/about">] About
module Templating =
open WebSharper.UI.Html
type MainTemplate = Templating.Template<"Main.html">
// Compute a menubar where the menu item for the given endpoint is active
let MenuBar (ctx: Context<EndPoint>) endpoint : Doc list =
let ( => ) txt act =
li [if endpoint = act then yield attr.``class`` "active"] [
a [attr.href (ctx.Link act)] [text txt]
]
[
"Home" => EndPoint.Home
"About" => EndPoint.About
]
let Main ctx action (title: string) (body: Doc list) =
Content.Page(
MainTemplate()
.Title(title)
.MenuBar(MenuBar ctx action)
.Body(body)
.Doc()
)
module Site =
open WebSharper.UI.Html
let HomePage ctx =
Templating.Main ctx EndPoint.Home "Home" [
h1 [] [text "Say Hi to the server!"]
div [] [client <@ Client.Main() @>]
]
let AboutPage ctx =
Templating.Main ctx EndPoint.About "About" [
h1 [] [text "About"]
p [] [text "This is a template WebSharper client-server application."]
]
let Main =
Application.MultiPage (fun ctx endpoint ->
match endpoint with
| EndPoint.Home -> HomePage ctx
| EndPoint.About -> AboutPage ctx
)
open WebSharper.Suave
open Suave.Web
open Suave.Http
let myConfig = { defaultConfig with bindings = [HttpBinding.createSimple HTTP "192.168.2.17" 9000]}
do
startWebServer
defaultConfig
(WebSharperAdapter.ToWebPart(Main, RootDirectory = @"../.."))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment