Working dotenv configuration
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -5,7 +5,7 @@ | ||||
| Dockerfile | ||||
| WD | ||||
| bin/ | ||||
| data/ | ||||
| data/posts | ||||
| dist* | ||||
| docker-stack.yml | ||||
| result | ||||
|  | ||||
							
								
								
									
										2
									
								
								data/.env.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								data/.env.example
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| APPLICATIONPORT="3000" | ||||
| BLOGTITLE="Anon's Blog" | ||||
| @ -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 | ||||
|  | ||||
							
								
								
									
										17
									
								
								src/Core/Configuration.hs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/Core/Configuration.hs
									
									
									
									
									
										Normal 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" | ||||
| @ -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 | ||||
|  | ||||
| @ -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) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user