For serving directories of static assets, Revel provides the static built in module,which contains a singleStaticcontroller. Static.Serve action takes two parameters:

Config

The static moduleis optional is enabled by default.

By default when you create a new project the followingconfiguration options are set in the app.conf file:

  1. module.static = github.com/revel/modules/static

Additionally, these will be set in routes conf/routes:

  1. GET /public/*filepath Static.Serve("public")
  2. GET /favicon.ico Static.Serve("public","img/favicon.png")

As defined in the route manual the syntax used for defininga route is Controller.Action(prefix,filepath). So the word publichas nothing to do with visibility, it follows the defaultdirectory organization

  • prefix (string) - A (relative or absolute) path to the asset root.
  • filepath (string) - A relative path that specifies the requested file.
    Bad example
  1. GET /img/icon.png Static.Serve("public", "img/icon.png") << space causes error

Important:For the two parameters version of Static.Serve, blank spaces are not allowed between" and , due to how encoding/csv works.

Static content can only be served from within the application root for security reasons. To include external assets consider symbolic links or a git submodule

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.

GitHub Labels

原文: https://revel.github.io/modules/static.html