You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--| Function to read and parse options from the environment
66
65
readOptions::IOAppConfig
67
66
readOptions =
68
-
Env.parse (header "You need to configure some environment variables to start the service.") $
69
-
AppConfig<$> var (str <=< nonempty) "PGWS_DB_URI" (help "String to connect to PostgreSQL")
70
-
<*> optional (var str "PGWS_ROOT_PATH" (help "Root path to serve static files, unset to disable."))
71
-
<*> var str "PGWS_HOST" (def "*4"<> helpDef show<> help "Address the server will listen for websocket connections")
72
-
<*> var auto "PGWS_PORT" (def 3000<> helpDef show<> help "Port the server will listen for websocket connections")
73
-
<*> var str "PGWS_LISTEN_CHANNEL" (def "postgres-websockets-listener"<> helpDef show<> help "Master channel used in the database to send or read messages in any notification channel")
74
-
<*> optional (var str "PGWS_META_CHANNEL" (help "Websockets channel used to send events about the server state changes."))
75
-
<*> var str "PGWS_JWT_SECRET" (help "Secret used to sign JWT tokens used to open communications channels")
76
-
<*> var auto "PGWS_JWT_SECRET_BASE64" (def False<> helpDef show<> help "Indicate whether the JWT secret should be decoded from a base64 encoded string")
77
-
<*> var auto "PGWS_POOL_SIZE" (def 10<> helpDef show<> help "How many connection to the database should be used by the connection pool")
78
-
<*> var auto "PGWS_RETRIES" (def 5<> helpDef show<> help "How many times it should try to connect to the database on startup before exiting with an error")
79
-
<*> var auto "PGWS_CHECK_LISTENER_INTERVAL" (def 0<>helpDef show<> help "Interval for supervisor thread to check if listener connection is alive. 0 to disable it.")
67
+
Env.parse (header "You need to configure some environment variables to start the service.") $
68
+
AppConfig<$> var (str <=< nonempty) "PGWS_DB_URI" (help "String to connect to PostgreSQL")
69
+
<*> optional (var str "PGWS_ROOT_PATH" (help "Root path to serve static files, unset to disable."))
70
+
<*> var str "PGWS_HOST" (def "*4"<> helpDef show<> help "Address the server will listen for websocket connections")
71
+
<*> var auto "PGWS_PORT" (def 3000<> helpDef show<> help "Port the server will listen for websocket connections")
72
+
<*> var str "PGWS_LISTEN_CHANNEL" (def "postgres-websockets-listener"<> helpDef show<> help "Master channel used in the database to send or read messages in any notification channel")
73
+
<*> optional (var str "PGWS_META_CHANNEL" (help "Websockets channel used to send events about the server state changes."))
74
+
<*> var str "PGWS_JWT_SECRET" (help "Secret used to sign JWT tokens used to open communications channels")
75
+
<*> var auto "PGWS_JWT_SECRET_BASE64" (def False<> helpDef show<> help "Indicate whether the JWT secret should be decoded from a base64 encoded string")
76
+
<*> var auto "PGWS_POOL_SIZE" (def 10<> helpDef show<> help "How many connection to the database should be used by the connection pool")
77
+
<*> var auto "PGWS_RETRIES" (def 5<> helpDef show<> help "How many times it should try to connect to the database on startup before exiting with an error")
78
+
<*>optional (var auto "PGWS_CHECK_LISTENER_INTERVAL" (helpDef show<> help "Interval for supervisor thread to check if listener connection is alive. 0 to disable it."))
80
79
81
80
loadDatabaseURIFile::AppConfig->IOAppConfig
82
-
loadDatabaseURIFile conf@AppConfig{..} =
81
+
loadDatabaseURIFile conf@AppConfig{..} =
83
82
case stripPrefix "@" configDatabase of
84
-
Nothing->pure conf
83
+
Nothing->pure conf
85
84
Just filename -> setDatabase . strip <$>readFile (toS filename)
86
85
where
87
86
setDatabase uri = conf {configDatabase = uri}
88
87
89
88
loadSecretFile::AppConfig->IOAppConfig
90
89
loadSecretFile conf = extractAndTransform secret
91
90
where
92
-
secret = decodeUtf8 $ configJwtSecret conf
93
-
isB64 = configJwtSecretIsBase64 conf
91
+
secret = decodeUtf8 $ configJwtSecret conf
92
+
isB64 = configJwtSecretIsBase64 conf
94
93
95
94
extractAndTransform::Text->IOAppConfig
96
95
extractAndTransform s =
97
-
fmap setSecret $ transformString isB64 =<<
98
-
case stripPrefix "@" s of
99
-
Nothing->return. encodeUtf8 $ s
100
-
Just filename -> chomp <$>BS.readFile (toS filename)
96
+
fmap setSecret $
97
+
transformString isB64
98
+
=<<case stripPrefix "@" s of
99
+
Nothing->return. encodeUtf8 $ s
100
+
Just filename -> chomp <$>BS.readFile (toS filename)
--| Given a configuration and a shutdown action (performed when the Multiplexer's listen connection dies) produces the context necessary to run sessions
0 commit comments