Make generated CSS files group-readable so that nginx can actually serve them without me manually chmodding

This commit is contained in:
Danielle McLean 2017-10-10 00:19:23 +11:00
parent c517baac1c
commit 035cc1de3b
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
2 changed files with 11 additions and 1 deletions

View file

@ -53,6 +53,7 @@ dependencies:
- foreign-store >=0.2 && <0.3
- slug >=0.1 && <0.2
- split >=0.2 && <0.3
- unix >=2.7 && <2.8
- yesod-auth-hashdb >=1.6.2 && <1.7
- yesod-newsfeed >=1.6 && <1.7
- yesod-sitemap >=1.4 && <1.5

View file

@ -25,7 +25,9 @@ import Entry.Kind ( EntryKind, allEntryKinds, pluralise )
import Data.Aeson ( encode, object )
import qualified Text.Blaze.Internal as B
import qualified Data.Text as T
import qualified Data.Text.Lazy.Encoding as E
import qualified System.Posix.Files as F
-- | The foundation datatype for your application. This can be a good place to
-- keep settings and values requiring initialization before your application
@ -130,7 +132,7 @@ instance Yesod App where
addStaticContent ext mime content = do
master <- getYesod
let staticDir = appStaticDir $ appSettings master
addStaticContentExternal
external <- addStaticContentExternal
minifym
genFileName
staticDir
@ -138,6 +140,13 @@ instance Yesod App where
ext
mime
content
case external of
(Just (Right (StaticR (StaticRoute filePath _), _))) -> liftIO $ do
let staticPath = ((staticDir ++ "/") ++) . T.unpack . T.intercalate "/" $ filePath
mode <- F.fileMode <$> F.getFileStatus staticPath
F.setFileMode staticPath $ mode `F.unionFileModes` F.groupReadMode
_ -> return ()
return external
where
-- Generate a unique filename based on the content itself
genFileName lbs = "autogen-" ++ base64md5 lbs