Search code examples
f#single-page-applicationwebsharper

How to execute configuration code in a WebSharper SPA without using the JavaScript attribute


I want to evaluate some values that I read in from a config source, and bake those values into my WebSharper SPA. With these value I want to generate the SPA for each of my customers and use the SPA in a different mobile app for each customer.

When I try to do this, WebSharper expects me to decorate my module with the JavaScript attribute.

How can I provide configuration values without having to decorate my module?

Example:

type Config = { brandedUrl : Uri } // This is configurable depending on customer

module Configuration = // I don't want to decorate this module with JavaScript
  // Some code that reads a config file, yml maybe
  let get : Config = getConfig // extract vals from file

[<JavaScript>]
module Navbar =
  let navbar = divAttr [ img [ src Configuration.get.brandedUrl ] ] 

Solution

  • Can be achieved using built in WebSharper functionality, demonstrated here: https://github.com/Kimserey/ConfigTest