aboutsummaryrefslogtreecommitdiff
path: root/src/server/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Main.hs')
-rw-r--r--src/server/Main.hs85
1 files changed, 46 insertions, 39 deletions
diff --git a/src/server/Main.hs b/src/server/Main.hs
index 2ae319b..3033f58 100644
--- a/src/server/Main.hs
+++ b/src/server/Main.hs
@@ -10,44 +10,51 @@ import Application
import Model.Database (runMigrations)
+import Config
+
main :: IO ()
main = do
- runMigrations
- scotty 3000 $ do
-
- middleware $
- staticPolicy (noDots >-> addBase "public")
-
- get "/" $
- getIndexAction
-
- post "/signIn" $ do
- login <- param "login" :: ActionM Text
- signInAction login
-
- get "/validateSignIn" $ do
- token <- param "token" :: ActionM Text
- validateSignInAction token
-
- get "/userName" $
- getUserName
-
- get "/payments" $
- getPaymentsAction
-
- post "/payment/add" $ do
- name <- param "name" :: ActionM Text
- cost <- param "cost" :: ActionM Int
- createPaymentAction name cost
-
- post "/signOut" $
- signOutAction
-
- get "/users" getUsersAction
- post "/user/add" $ do
- email <- param "email" :: ActionM Text
- name <- param "name" :: ActionM Text
- addUserAction email name
- post "/user/delete" $ do
- email <- param "email" :: ActionM Text
- deleteUserAction email
+ config <- getConfig "config.txt"
+ case config of
+ Left error ->
+ putStrLn error
+ Right config -> do
+ runMigrations
+ scotty (port config) $ do
+
+ middleware $
+ staticPolicy (noDots >-> addBase "public")
+
+ get "/" $
+ getIndexAction
+
+ post "/signIn" $ do
+ login <- param "login" :: ActionM Text
+ signInAction config login
+
+ get "/validateSignIn" $ do
+ token <- param "token" :: ActionM Text
+ validateSignInAction token
+
+ get "/userName" $
+ getUserName
+
+ get "/payments" $
+ getPaymentsAction
+
+ post "/payment/add" $ do
+ name <- param "name" :: ActionM Text
+ cost <- param "cost" :: ActionM Int
+ createPaymentAction name cost
+
+ post "/signOut" $
+ signOutAction
+
+ get "/users" getUsersAction
+ post "/user/add" $ do
+ email <- param "email" :: ActionM Text
+ name <- param "name" :: ActionM Text
+ addUserAction email name
+ post "/user/delete" $ do
+ email <- param "email" :: ActionM Text
+ deleteUserAction email