diff options
| author | Joris Guyonvarch | 2015-08-08 19:50:58 +0200 | 
|---|---|---|
| committer | Joris Guyonvarch | 2015-08-08 19:50:58 +0200 | 
| commit | a4f60df0f3b72553380bdd3ca960abf42048ed7e (patch) | |
| tree | cf30e45801e68129eb7b1c990b142a412fa98e30 /src/server/Main.hs | |
| parent | cd7ca2fcc7a2f4a10235f8807a89c8d6549b99bf (diff) | |
Getting the hostname and the port in config file
Diffstat (limited to 'src/server/Main.hs')
| -rw-r--r-- | src/server/Main.hs | 85 | 
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 | 
