# README
For serving directories of static assets, Revel provides the static built in module, which contains a single Static controller.
Static.Serve action takes two parameters:
(file path relative to app)
, (exact file name)
Static.ServeModule action takes three parameters:
(module name)
, (file path relative to app)
, (exact file name)
Static.ServeDir action takes one parameter:
(file path relative to app)
Config
The static
module
is optional is enabled by default.
By default when you create a new project the following configuration options are set in the file:
module.static = github.com/revel/modules/static
Additionally, these will be set in routes conf/routes
:
GET /public/*filepath Static.Serve("public")
GET /favicon.ico Static.Serve("public","img/favicon.png")
GET /public/*filepath Static.ServeDir("public")
GET /public Static.ServeDir("public")
The syntax used for defining
a route is Controller.Action(prefix,filepath)
. So the word public
has nothing to do with visibility, it follows the default
directory
prefix
(string) - A (relative or absolute) path to the asset root.filepath
(string) - A relative path that specifies the requested file.
Bad example
GET /img/icon.png Static.Serve("public", "img/icon.png") << space causes error
For the two parameters version of
Static.Serve
, blank spaces are not allowed between
"
and ,
due to how encoding/csv
works.
Best Practices
Although Revel does serve out static content in the most efficient way it can, it makes more sense for your web server to serve the static files directly.