Created
December 1, 2015 12:51
-
-
Save bradphelan/c1072664c8560c4c9966 to your computer and use it in GitHub Desktop.
problem with websharper suave integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace bookman | |
open WebSharper | |
open WebSharper.Sitelets | |
open WebSharper.UI.Next | |
open WebSharper.UI.Next.Server | |
type EndPoint = | |
| [<EndPoint "/">] Home | |
| [<EndPoint "/about">] About | |
| [<EndPoint "/booking">] Booking | |
module Templating = | |
open WebSharper.UI.Next.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 = | |
liAttr [if endpoint = act then yield attr.``class`` "active"] [ | |
aAttr [attr.href (ctx.Link act)] [text txt] | |
] | |
[ | |
li ["Home" => EndPoint.Home] | |
li ["About" => EndPoint.About] | |
li ["Booking" => EndPoint.Booking] | |
] | |
let Main ctx action title body = | |
Content.Page( | |
MainTemplate.Doc( | |
title = title, | |
menubar = MenuBar ctx action, | |
body = body | |
) | |
) | |
module Site = | |
open WebSharper.UI.Next.Html | |
let HomePage ctx = | |
Templating.Main ctx EndPoint.Home "Home" [ | |
h1 [text "Say Hi to the server!"] | |
div [client <@ Client.Main() @>] | |
div [text "kuck" ] | |
] | |
let AboutPage ctx = | |
Templating.Main ctx EndPoint.About "About" [ | |
h1 [text "About"] | |
p [text "This is a template WebSharper client-server application."] | |
] | |
let BookingPage ctx = | |
Templating.Main ctx EndPoint.Booking "Booking" [ | |
h1 [text "Booking"] | |
p [text "Please set up your booking agent"] | |
] | |
let Main = | |
Application.MultiPage (fun ctx endpoint -> | |
match endpoint with | |
| EndPoint.Home -> HomePage ctx | |
| EndPoint.About -> AboutPage ctx | |
| EndPoint.Booking -> BookingPage ctx | |
) | |
open WebSharper.Suave | |
open Suave.Web | |
open WebSharper.Suave | |
open Suave.Http | |
open Suave.Web | |
open Suave.Types | |
open Suave.Log | |
open Suave.Logging | |
let logger = new Suave.Logging.Loggers.ConsoleWindowLogger(LogLevel.Verbose) | |
let serverConfig = | |
let port = 8080 | |
{ defaultConfig with | |
logger = logger | |
bindings = [ HttpBinding.mk' HTTP "127.0.0.1" port ] } | |
let mainPart = WebSharperAdapter.ToWebPart Main | |
let homePart = Files.browseHome | |
let allParts = | |
choose [ | |
mainPart | |
homePart | |
] | |
do startWebServer serverConfig allParts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment