const mixinafBedSheet::PodHandler

afBedSheet::PodHandler : afBedSheet::ClientAssetProducer

(Service) - A ClientAssetProducer that maps URLs to file resources inside pods.

To access a pod resource use URLs in the format:


By default the baseUrl is /pod/ which means you should always be able to access the flux icon.


Change the base url in the application defaults:

@Contribute { serviceType=ApplicationDefaults# } 
Void contributeAppDefaults(Configuration config) {
    config[BedSheetConfigIds.podHandlerBaseUrl] = `/some/other/url/`

Set the base url to null to disable the serving of pod resources.

Serve Fantom Code

Fantom compiles all classes in a pod annotated with the @Js facet into a Javascript file that is saved in the pod. These pod .js files can then be served up with PodHandler allowing you execute Fantom code in the browser.

Here is an example that calls alert() via Fantom's DOM pod. To run, just serve the example as static HTML:

<!DOCTYPE html>
    <script type="text/javascript" src="/pod/sys/sys.js"></script>
    <script type="text/javascript" src="/pod/gfx/gfx.js"></script>
    <script type="text/javascript" src="/pod/web/web.js"></script>
    <script type="text/javascript" src="/pod/dom/dom.js"></script>
    <h1>Old Skool Example</h1>

    <script type="text/javascript">
        fan.dom.Win.cur().alert("Hello Mum!");

Note that the order in which the pod .js files are listed is very important; each pod's dependencies must be listed before the pod itself.

Fantom code may also be executed via the web::WebUtil.jsMain() method.

A much cleaner way injecting Fantom code is to use the Duvet library which uses RequireJS to wrap up the Fantom code as dependency managed Javascript modules.

Resource Whitelist

Because pods may contain sensitive data, the entire contents of all the pods are NOT available by default. Oh no! PodHandler has a whitelist of Regexes that specify which pod files are allowed to be served. If a pod resource doesn't match a regex, it doesn't get served.

By default only a handful of files with common web extensions are allowed. These include:

.      web files: .css .htm .html .js .xhtml
     image files: .bmp .gif .ico .jpg .png
     sound files: .mp3 .ogg .wav .opus
  web font files: .eot .otf .svg .ttf .woff
     other files: .csv .txt .xml

To add or remove whitelist regexs, contribute to PodHandler:

@Contribute { serviceType=PodHandler# } 
static Void contributePodHandler(Configuration conf) {
    conf.remove(".txt")                      // prevent .txt files from being served
    conf["acmePodFiles"] = "^fan://acme/.*$" // serve all files from the acme pod


abstract Uri? baseUrl()

The local URL under which pod resources are served.

Set by BedSheetConfigIds.podHandlerBaseUrl, defaults to /pods/.



abstract ClientAsset? fromLocalUrl(Uri localUrl, Bool checked := true)

Given a local URL (a simple URL relative to the WebMod), this returns a corresponding (cached) FileAsset. Throws ArgErr if the URL is not mapped or does not exist.



abstract ClientAsset? fromPodResource(Uri podResource, Bool checked := true)

Given a pod resource file, this returns a corresponding (cached) FileAsset. The URI must adhere to the fan://<pod>/<file> scheme notation. Throws ArgErr if the URL is not mapped or does not exist.