f# - Suave serve static files -


i'll serve files in 'public' folder suave

inside public have:

/index.html /styles/main.css /scripts/app.js /images/*.(png|jpg) 

do use homefolder? or how work? public folder need copied next executable in bin folder? code snippet appreciated. thanks.

edit:

the solution looks this:

open suave open suave.filters open suave.operators open suave.successful open system.io  let app =      choose [         >=> choose             [path "/" >=> ok "test" ; files.browsehome]         post >=> choose             [path "/foo" >=> ok "thanks"]     ]  let myhomefolder = path.combine(directory.getcurrentdirectory(), "public")   let cfg = {      defaultconfig         homefolder = some(myhomefolder)     }  [<entrypoint>] let main argv =      printfn "%a" argv     startwebserver cfg app     system.console.readline() |> ignore     0 // return integer exit code 

i found quite hard it's not documented. didn't find blog carsten linked above managed come after trawling through suave source code , examples in github repo:

open suave open suave.operators  let app =     choose         [ filters.get >=> choose              [ filters.path "/" >=> (                   "my main page"                   |> successful.ok)                files.browsehome ] ] // <-- important part  [<entrypoint>] let main x =     web.startwebserver web.defaultconfig app |> ignore     0 

i used browsehome because console app , wanted serve files exe directory. think you'll want use browse (source code)

and here examples may find useful.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -