const mixinafBedSheet::FileHandler

afBedSheet::FileHandler

(Service) - Request Handler that maps URIs to files on the file system.

Example, to map all uris prefixed with /pub/ to files under the <app>/etc/web/ directory, add the following to your AppModule:

@Contribute { serviceType=FileHandler# }
static Void contributeFileHandler(MappedConfig conf) {
  conf[`/pub/`] = `etc/web/`.toFile
}

Use the fromServerFile() method to generate URIs to be used by the browser. Example:

// note how the file uses a relative URI
fromServerFile(`etc/web/css/mystyle.css`.toFile) // --> `/pub/css/mystyle.css` 

Now when the browser requests /pub/css/mystyle.css, BedSheet will return the file <app>/etc/web/css/mystyle.css.

It is common to serve files from the root uri:

conf[`/`] = `etc/web/`

Route mappings are automatically added to the Routes service, and are sandwiched in between FileHanderStart and FileHandlerEnd place holders. Use these when Route precedence is important:

@Contribute { serviceId="Routes" }
static Void contributeRoutes(OrderedConfig config) {

  // this Route will be served in place of the file 'uri1.txt'
  config.addOrdered("uri1", Route(`/uri1.txt`, ...), ["before: FileHandlerStart"])

  // this Route will be served if there is no file called 'uri.txt'
  config.addOrdered("uri2", Route(`/uri2.txt`, ...), ["after: FileHandlerEnd"])
}

@uses MappedConfig of Uri:File

directoryMappings

Source

abstract Uri:File directoryMappings()

Returns the map of uri to directory mappings

fromClientUri

Source

abstract File? fromClientUri(Uri assetUri, Bool checked)

Returns the server file that the client-side asset URI maps to.

If checked is true throw Err if the file does not exist, else return null.

fromServerFile

Source

abstract Uri fromServerFile(File assetFile)

Returns the client URI that corresponds to the given asset file.

Throws a NotFoundErr if the file does not reside in a mapped directory.

service

Source

abstract File? service(Uri remainingUri)

Returns a File on the file system as mapped from the given uri, or null if the file does not exist.