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/` }
Now all requests to /pub/css/mystyle.css
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