Tutorial: Static Assets

Static Assets

Most applications have some form of static assets that need to be served (images, stylesheets, front-end scripts, &c.). For sake of simplicity, rather than defining routes for all of these static assets, Flitter makes a simple static webserver available for your application.

By default, assets placed in the app/assets/ directory will be served statically at the /assets/ endpoint on your application.

For example, say you have the file app/assets/my_styles.css, then you can access this file from your application at //my.app.url/assets/my_styles.css.

Favicon Support

Flitter makes use of the express-favicon package to serve a favicon.ico file automatically. To do so, place your favicon at app/assets/favicon.ico.

StaticUnit

If, for some reason, you need to programmatically get the path to the static asset directory, you can do so using the static service. (See: module:libflitter/static/StaticUnit~StaticUnit)

> _services.static.static_asset_directory // "/path_to_flitter/app/assets"