diff --git a/Purr.cabal b/Purr.cabal index 8ec1f0a..e3d5401 100644 --- a/Purr.cabal +++ b/Purr.cabal @@ -16,8 +16,7 @@ extra-source-files: executable Purr main-is: Main.hs hs-source-dirs: - app - , src + src default-extensions: ConstraintKinds DeriveGeneric @@ -64,5 +63,4 @@ executable Purr Feature.Sharing.HTTP Feature.Sharing.SQLite Feature.Sharing.Templates - Lib default-language: Haskell2010 diff --git a/app/Main.hs b/app/Main.hs deleted file mode 100644 index e4a53d8..0000000 --- a/app/Main.hs +++ /dev/null @@ -1,7 +0,0 @@ -module Main where - -import Prelude -import qualified Lib - -main :: IO () -main = Lib.main diff --git a/src/Core/Configuration.hs b/src/Core/Configuration.hs index 77a146d..848e1bb 100644 --- a/src/Core/Configuration.hs +++ b/src/Core/Configuration.hs @@ -1,21 +1,22 @@ module Core.Configuration ( adminEmail, appPort , confLinkLength, dataPath, dbPath , encKey, getRuntimeEnvironment - , keyFileInit, main) where + , keyFileInit, init) where import qualified Data.ByteString as B import Control.Monad (mapM) +import Configuration.Dotenv import Core.Types import Crypto.Saltine.Core.SecretBox (newKey) import Crypto.Saltine.Class (encode) -import Configuration.Dotenv +import Prelude hiding (init) import System.Directory (doesFileExist) import System.Environment (getEnv, lookupEnv) -- Load environment variables from dotenv file if required -main :: IO () -main = do +init :: IO () +init = do reqEnvLookup <- getRequiredEnv if (Nothing `elem` reqEnvLookup) then checkEnvFile requiredEnvVars diff --git a/src/Core/SQLite.hs b/src/Core/SQLite.hs index 7374b6c..5eb6734 100644 --- a/src/Core/SQLite.hs +++ b/src/Core/SQLite.hs @@ -6,12 +6,13 @@ import Core.Types import Data.ByteString as B import Database.SQLite.Simple import Database.SQLite.Simple.FromRow +import Prelude hiding (init) import qualified Data.Text as T -- Set up SQLite database table when Purr starts if it doesn't already exist -main :: IO () -main = do +init :: IO () +init = do conn <- open dbPath execute_ conn "CREATE TABLE IF NOT EXISTS pws\ diff --git a/src/Lib.hs b/src/Main.hs similarity index 81% rename from src/Lib.hs rename to src/Main.hs index a6554fd..6e00be9 100644 --- a/src/Lib.hs +++ b/src/Main.hs @@ -1,4 +1,4 @@ -module Lib ( main ) where +module Main ( main ) where import qualified Core.Configuration as Configuration import qualified Core.HTTP as HTTP @@ -16,17 +16,16 @@ main = do -- Initialize the RNG used for sodium encryption (Saltine library) sodiumInit {- Initialize our dotenv configuration which reads from a .env configuration - file unless the PURRNOFILE env var exists already. -} - Configuration.main + if any required variables are missing from the provided environment -} + Configuration.init {- Initialize the encryption key file if it doesn't exist yet or use the existing key -} Configuration.keyFileInit {- Initialize our database by ensuring the SQLite file exists and has tables setup as the application expects -} - DB.main + DB.init {- Get the configured port to run on and start the Scotty webserver app defined in HTTP.app -} - appPortStr <- Configuration.appPort + port <- Configuration.appPort env <- Configuration.getRuntimeEnvironment - let appPort = read appPortStr :: Int - scotty appPort (HTTP.app env) + scotty (read port) (HTTP.app env)