Add configurable assets folder

This adds a server-assets-folder configuration which allows overriding the assets bundled to the binary.
This commit is contained in:
Daniel Malon 2015-02-26 21:29:00 +00:00
parent b9383265a4
commit 447cf710af
2 changed files with 17 additions and 1 deletions

View file

@ -9,6 +9,12 @@ port=":80"
# key="" # key=""
# cert="" # cert=""
#####################################################################
# Assets configuration
#
# [server.assets]
# folder=""
# [session] # [session]
# secret="" # secret=""
# expires="" # expires=""

View file

@ -55,6 +55,8 @@ var (
sslcrt = config.String("server-ssl-cert", "") sslcrt = config.String("server-ssl-cert", "")
sslkey = config.String("server-ssl-key", "") sslkey = config.String("server-ssl-key", "")
assets_folder = config.String("server-assets-folder", "")
workers *pool.Pool workers *pool.Pool
worker *director.Director worker *director.Director
pub *pubsub.PubSub pub *pubsub.PubSub
@ -125,7 +127,15 @@ func main() {
pub = pubsub.NewPubSub() pub = pubsub.NewPubSub()
// create handler for static resources // create handler for static resources
assetserve := http.FileServer(rice.MustFindBox("app").HTTPBox()) // if we have a configured assets folder it takes precedence over the assets
// bundled to the binary
var assetserve http.Handler
if *assets_folder != "" {
assetserve = http.FileServer(http.Dir(*assets_folder))
} else {
assetserve = http.FileServer(rice.MustFindBox("app").HTTPBox())
}
http.Handle("/robots.txt", assetserve) http.Handle("/robots.txt", assetserve)
http.Handle("/static/", http.StripPrefix("/static", assetserve)) http.Handle("/static/", http.StripPrefix("/static", assetserve))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {