Remove redundant entry point; adjust comments in main init; update init function names from 'main'
This commit is contained in:
parent
19c6801d12
commit
3863ddf42e
@ -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
|
||||
|
@ -1,7 +0,0 @@
|
||||
module Main where
|
||||
|
||||
import Prelude
|
||||
import qualified Lib
|
||||
|
||||
main :: IO ()
|
||||
main = Lib.main
|
@ -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
|
||||
|
@ -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\
|
||||
|
@ -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)
|
Loading…
x
Reference in New Issue
Block a user