Skip to content

lujiacn/revstatic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
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. # revstatic

About

folk of revel/modules/static

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published