Commit f21104e9 authored by Ibnu Daru Aji's avatar Ibnu Daru Aji

added static files settings.

parent f30a18c6
......@@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: d861629c79fdb1cf06fd75ce62386af16a3660c0912ab0ae3a6ec30a93346e12
-- hash: e0ee5a254ef7241a3e87a0539079ef691434a9dc90751c9daf2b968912c9042c
name: Cirkeltrek
version: 0.0.0
......@@ -18,6 +18,7 @@ library
Model.Grouping
Profile
Settings
Settings.StaticFiles
other-modules:
Paths_Cirkeltrek
hs-source-dirs:
......@@ -31,6 +32,7 @@ library
, esqueleto
, fast-logger
, file-embed
, hjsmin
, http-client
, http-client-tls
, monad-logger
......@@ -69,6 +71,7 @@ executable Cirkeltrek
, esqueleto
, fast-logger
, file-embed
, hjsmin
, http-client
, http-client-tls
, monad-logger
......@@ -107,6 +110,7 @@ executable Seed
, esqueleto
, fast-logger
, file-embed
, hjsmin
, http-client
, http-client-tls
, monad-logger
......
......@@ -10,6 +10,7 @@ dependencies:
- esqueleto
- fast-logger
- file-embed
- hjsmin
- http-client
- http-client-tls
- monad-logger
......
......@@ -13,16 +13,19 @@ import ClassyPrelude.Yesod
import Database.Persist.Sql
import Network.HTTP.Client
import Text.Hamlet
import Text.Jasmine
import Yesod.Auth
import Yesod.Auth.HashDB
import Yesod.Auth.Message
import Yesod.Core
import Yesod.Core.Types
import Yesod.Default.Util
import Yesod.Form
import Yesod.Static
import Model
import Settings
import Settings.StaticFiles
data App = App
{ appSettings :: ApplicationSettings
......@@ -36,6 +39,7 @@ mkYesodData
"App"
[parseRoutes|
/ HomeR GET
/static StaticR Static appStatic
/auth SigninR Auth getAuth
/profile ProfileR GET
|]
......@@ -51,16 +55,33 @@ instance Yesod App where
Just root -> root
makeSessionBackend _ = Just <$> defaultClientSessionBackend (60 * 5) "config/client-session-key.aes"
yesodMiddleware = defaultYesodMiddleware
addStaticContent ext mime content = do
yes <- getYesod
let statdir = appStaticDir $ appSettings yes
addStaticContentExternal
minifym
genFilename
statdir
(StaticR . flip StaticRoute [])
ext
mime
content
where
genFilename lbs = "autogen-" ++ base64md5 lbs
defaultLayout widget = do
master <- getYesod
maut <- maybeAuth
mmessage <- getMessage
pagecontent <- widgetToPageContent $ do
addStylesheet $ StaticR css_main_css
addStylesheet $ StaticR css_milligram_min_css
addStylesheet $ StaticR css_main_css
$(widgetFile "def")
withUrlRenderer $(hamletFile "templates/wrapper.hamlet")
authRoute _ = Just $ SigninR LoginR
isAuthorized (SigninR _) _ = return Authorized
isAuthorized HomeR _ = return Authorized
isAuthorized (StaticR _) _ = return Authorized
isAuthorized ProfileR _ = isLoggedIn
isLoggedIn :: Handler AuthResult
......
......@@ -16,6 +16,7 @@ import Language.Haskell.TH.Syntax
import Network.Wai.Handler.Warp
import Yesod.Default.Config2
import Yesod.Default.Util
import Yesod.Static
data ApplicationSettings = ApplicationSettings
{ appStaticDir :: String
......@@ -67,3 +68,4 @@ widgetFile =
where
widgetFileSettings :: WidgetFileSettings
widgetFileSettings = def
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Settings.StaticFiles where
import Yesod.Static
import Settings
staticFiles (appStaticDir compileTimeAppSettings)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment