Enable cache for 1 hour for static assets

This commit is contained in:
Alexandre Aubin 2019-03-19 16:52:43 +01:00
parent 23e78c2c39
commit 32a9229ef4
2 changed files with 15 additions and 5 deletions

View file

@ -150,7 +150,13 @@ then
and (not ngx.var.http_referer and (not ngx.var.http_referer
or hlp.string.starts(ngx.var.http_referer, conf.portal_url))) or hlp.string.starts(ngx.var.http_referer, conf.portal_url)))
then then
-- If this is an asset, enable caching
if hlp.string.starts(ngx.var.uri, conf["portal_path"].."assets")
then
return hlp.serve(ngx.var.uri, "static_asset")
else
return hlp.serve(ngx.var.uri) return hlp.serve(ngx.var.uri)
end
-- If all the previous cases have failed, redirect to portal -- If all the previous cases have failed, redirect to portal
@ -318,7 +324,7 @@ end
function serveAsset(shortcut, full) function serveAsset(shortcut, full)
if string.match(ngx.var.uri, "^"..shortcut.."$") then if string.match(ngx.var.uri, "^"..shortcut.."$") then
hlp.serve("/yunohost/sso/assets/"..full) hlp.serve("/yunohost/sso/assets/"..full, "static_asset")
end end
end end

View file

@ -437,7 +437,7 @@ end
-- --
-- Takes an URI, and returns file content with the proper HTTP headers. -- Takes an URI, and returns file content with the proper HTTP headers.
-- It is used to render the SSOwat portal *only*. -- It is used to render the SSOwat portal *only*.
function serve(uri) function serve(uri, cache)
rel_path = string.gsub(uri, conf["portal_path"], "/") rel_path = string.gsub(uri, conf["portal_path"], "/")
-- Load login.html as index -- Load login.html as index
@ -505,8 +505,12 @@ function serve(uri)
flashs["win"] = nil flashs["win"] = nil
flashs["info"] = nil flashs["info"] = nil
if cache == "static_asset" then
ngx.header["Cache-Control"] = "public, max-age=3600"
else
-- Ain't nobody got time for cache -- Ain't nobody got time for cache
ngx.header["Cache-Control"] = "no-cache" ngx.header["Cache-Control"] = "no-cache"
end
-- Print file content -- Print file content
ngx.say(content) ngx.say(content)