Working dotenv configuration

This commit is contained in:
James Eversole 2024-02-18 13:41:43 -06:00
parent 3e81ea8fec
commit aea0e6dfc8
6 changed files with 29 additions and 9 deletions

2
.gitignore vendored
View File

@ -5,7 +5,7 @@
Dockerfile Dockerfile
WD WD
bin/ bin/
data/ data/posts
dist* dist*
docker-stack.yml docker-stack.yml
result result

2
data/.env.example Normal file
View File

@ -0,0 +1,2 @@
APPLICATIONPORT="3000"
BLOGTITLE="Anon's Blog"

View File

@ -16,12 +16,14 @@ executable sampu
build-depends: base build-depends: base
, bytestring >= 0.11.5.0 , bytestring >= 0.11.5.0
, commonmark >= 0.2.4 , commonmark >= 0.2.4
, dotenv >= 0.11.0.0
, lucid >= 2.11.0 , lucid >= 2.11.0
, twain >= 2.1.0.0 , twain >= 2.1.0.0
, wai-extra >= 3.0 && < 3.2 , wai-extra >= 3.0 && < 3.2
, warp == 3.3.25 , warp == 3.3.25
hs-source-dirs: src hs-source-dirs: src
other-modules: other-modules:
Core.Configuration
Core.Handlers Core.Handlers
Core.HTTP Core.HTTP
Core.Rendering Core.Rendering

17
src/Core/Configuration.hs Normal file
View File

@ -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"

View File

@ -1,5 +1,6 @@
module Core.HTTP where module Core.HTTP where
import qualified Core.Configuration as Conf
import qualified Core.Handlers as Handle import qualified Core.Handlers as Handle
import Network.Wai.Middleware.RequestLogger (logStdoutDev) import Network.Wai.Middleware.RequestLogger (logStdoutDev)
@ -8,7 +9,8 @@ import Web.Twain
main :: IO () main :: IO ()
main = do main = do
run appPort $ port <- Conf.appPort
run (read port :: Int) $
foldr ($) (notFound Handle.missing) app foldr ($) (notFound Handle.missing) app
-- Combine our Preprocessor Middlewares and Routes to create an App -- Combine our Preprocessor Middlewares and Routes to create an App
@ -25,7 +27,3 @@ routes =
[ get "/" Handle.index [ get "/" Handle.index
, get "/echo/:testParam" Handle.testRoute , get "/echo/:testParam" Handle.testRoute
] ]
-- This will be replaced with getEnv located in Configuration
appPort :: Port
appPort = 3000

View File

@ -1,6 +1,7 @@
module Main where module Main where
import qualified Core.HTTP as Core import qualified Core.HTTP as Core
import qualified Core.Configuration as Conf
main :: IO () main :: IO ()
main = Core.main main = Conf.main >>= (\_ -> Core.main)