mirror of
https://github.com/YunoHost/SSOwat.git
synced 2024-09-03 20:06:27 +02:00
Enable cache for 1 hour for static assets
This commit is contained in:
parent
23e78c2c39
commit
32a9229ef4
2 changed files with 15 additions and 5 deletions
10
access.lua
10
access.lua
|
@ -150,7 +150,13 @@ then
|
|||
and (not ngx.var.http_referer
|
||||
or hlp.string.starts(ngx.var.http_referer, conf.portal_url)))
|
||||
then
|
||||
return hlp.serve(ngx.var.uri)
|
||||
-- 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)
|
||||
end
|
||||
|
||||
|
||||
-- If all the previous cases have failed, redirect to portal
|
||||
|
@ -318,7 +324,7 @@ end
|
|||
|
||||
function serveAsset(shortcut, full)
|
||||
if string.match(ngx.var.uri, "^"..shortcut.."$") then
|
||||
hlp.serve("/yunohost/sso/assets/"..full)
|
||||
hlp.serve("/yunohost/sso/assets/"..full, "static_asset")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
10
helpers.lua
10
helpers.lua
|
@ -437,7 +437,7 @@ end
|
|||
--
|
||||
-- Takes an URI, and returns file content with the proper HTTP headers.
|
||||
-- It is used to render the SSOwat portal *only*.
|
||||
function serve(uri)
|
||||
function serve(uri, cache)
|
||||
rel_path = string.gsub(uri, conf["portal_path"], "/")
|
||||
|
||||
-- Load login.html as index
|
||||
|
@ -505,8 +505,12 @@ function serve(uri)
|
|||
flashs["win"] = nil
|
||||
flashs["info"] = nil
|
||||
|
||||
-- Ain't nobody got time for cache
|
||||
ngx.header["Cache-Control"] = "no-cache"
|
||||
if cache == "static_asset" then
|
||||
ngx.header["Cache-Control"] = "public, max-age=3600"
|
||||
else
|
||||
-- Ain't nobody got time for cache
|
||||
ngx.header["Cache-Control"] = "no-cache"
|
||||
end
|
||||
|
||||
-- Print file content
|
||||
ngx.say(content)
|
||||
|
|
Loading…
Reference in a new issue