diff --git a/.gitignore b/.gitignore index 7088499..e09ae66 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ Dockerfile WD bin/ -data/ +data/posts dist* docker-stack.yml result diff --git a/data/.env.example b/data/.env.example new file mode 100644 index 0000000..7719108 --- /dev/null +++ b/data/.env.example @@ -0,0 +1,2 @@ +APPLICATIONPORT="3000" +BLOGTITLE="Anon's Blog" diff --git a/sampu.cabal b/sampu.cabal index d0829dd..6aef47b 100644 --- a/sampu.cabal +++ b/sampu.cabal @@ -16,12 +16,14 @@ executable sampu build-depends: base , bytestring >= 0.11.5.0 , commonmark >= 0.2.4 + , dotenv >= 0.11.0.0 , lucid >= 2.11.0 , twain >= 2.1.0.0 , wai-extra >= 3.0 && < 3.2 , warp == 3.3.25 hs-source-dirs: src other-modules: + Core.Configuration Core.Handlers Core.HTTP Core.Rendering diff --git a/src/Core/Configuration.hs b/src/Core/Configuration.hs new file mode 100644 index 0000000..7634bb1 --- /dev/null +++ b/src/Core/Configuration.hs @@ -0,0 +1,17 @@ +module Core.Configuration where + +import Configuration.Dotenv +import System.Environment (getEnv, lookupEnv) + +main :: IO () +main = do + envFile <- lookupEnv "NOENVFILE" + case envFile of + Nothing -> loadFile defaultConfig + _ -> putStrLn "Not using dotenv" + +appPort :: IO String +appPort = getEnv "APPLICATIONPORT" + +appTitle :: IO String +appTitle = getEnv "BLOGTITLE" diff --git a/src/Core/HTTP.hs b/src/Core/HTTP.hs index fa5ca46..78f4eda 100644 --- a/src/Core/HTTP.hs +++ b/src/Core/HTTP.hs @@ -1,6 +1,7 @@ module Core.HTTP where -import qualified Core.Handlers as Handle +import qualified Core.Configuration as Conf +import qualified Core.Handlers as Handle import Network.Wai.Middleware.RequestLogger (logStdoutDev) import Network.Wai.Handler.Warp (Port, run) @@ -8,7 +9,8 @@ import Web.Twain main :: IO () main = do - run appPort $ + port <- Conf.appPort + run (read port :: Int) $ foldr ($) (notFound Handle.missing) app -- Combine our Preprocessor Middlewares and Routes to create an App @@ -25,7 +27,3 @@ routes = [ get "/" Handle.index , get "/echo/:testParam" Handle.testRoute ] - --- This will be replaced with getEnv located in Configuration -appPort :: Port -appPort = 3000 diff --git a/src/Main.hs b/src/Main.hs index 4820368..cdefdc6 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,6 +1,7 @@ module Main where -import qualified Core.HTTP as Core +import qualified Core.HTTP as Core +import qualified Core.Configuration as Conf main :: IO () -main = Core.main +main = Conf.main >>= (\_ -> Core.main)