Skip to content

Commit

Permalink
refactor(Main): simplify the getPort function by using readJSON_
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejsmolinski committed Aug 10, 2019
1 parent eeb5db3 commit f054ad8
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@ import Prelude
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Foreign (MultipleErrors)
import HTTP.Server as HTTPServer
import HTTP.Utils as HTTPUtils
import Logger as Logger
import Node.Process (lookupEnv)
import Orchestrator.FS (readFile)
import Orchestrator.JSON (fromJSON)
import Orchestrator.Main (makeId, makeSecret, runDefinitionWithIdAndSecret)
import Simple.JSON (readJSON)
import Simple.JSON (readJSON_)

getPort :: Effect Int
getPort = do
maybePort <- lookupEnv "PORT"
case maybePort of
case (maybePort >>= readJSON_) of
Nothing -> pure 8181
(Just portString) -> do
case (readJSON portString :: Either MultipleErrors Int) of
(Left _) -> pure 8181
(Right port) -> pure port
(Just port) -> pure port

main :: Effect Unit
main = do
Expand Down

0 comments on commit f054ad8

Please sign in to comment.