summaryrefslogtreecommitdiff
path: root/fig-frontend/src/Fig/Frontend/Utils.hs
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-11-07 22:37:32 -0500
committerLLLL Colonq <llll@colonq>2024-11-07 22:37:32 -0500
commit624f7ba8b2fcda6675951dd8d41dcc99017484cf (patch)
treeff1bcc3ee77c73e73c3e246bc8e18ce8f3aca004 /fig-frontend/src/Fig/Frontend/Utils.hs
parentbb3f54c297f480db32303e9ee78fb72c5418b77a (diff)
Rename fig-frontend to fig-web
(It was the backend anyway :3)
Diffstat (limited to 'fig-frontend/src/Fig/Frontend/Utils.hs')
-rw-r--r--fig-frontend/src/Fig/Frontend/Utils.hs53
1 files changed, 0 insertions, 53 deletions
diff --git a/fig-frontend/src/Fig/Frontend/Utils.hs b/fig-frontend/src/Fig/Frontend/Utils.hs
deleted file mode 100644
index 090c6ba..0000000
--- a/fig-frontend/src/Fig/Frontend/Utils.hs
+++ /dev/null
@@ -1,53 +0,0 @@
-{-# Language RecordWildCards #-}
-{-# Language ApplicativeDo #-}
-
-module Fig.Frontend.Utils
- ( FigFrontendException(..)
- , loadConfig
- , Config(..)
- , websocket
- , module Network.HTTP.Types.Status
- ) where
-
-import Fig.Prelude
-
-import Network.HTTP.Types.Status
-import qualified Network.Wai.Handler.WebSockets as Wai.WS
-import qualified Network.WebSockets as WS
-
-import qualified Web.Scotty as Sc
-
-import qualified Toml
-
-newtype FigFrontendException = FigFrontendException Text
- deriving (Show, Eq, Ord)
-instance Exception FigFrontendException
-
-data Config = Config
- { port :: !Int
- , assetPath :: !FilePath
- , clientId :: !Text
- , authToken :: !Text
- , dbHost :: !Text
- } deriving (Show, Eq, Ord)
-
-configCodec :: Toml.TomlCodec Config
-configCodec = do
- port <- Toml.int "port" Toml..= (\a -> a.port)
- assetPath <- Toml.string "asset_path" Toml..= (\a -> a.assetPath)
- clientId <- Toml.text "client_id" Toml..= (\a -> a.clientId)
- authToken <- Toml.text "auth_token" Toml..= (\a -> a.authToken)
- dbHost <- Toml.text "db_host" Toml..= (\a -> a.dbHost)
- pure $ Config{..}
-
-loadConfig :: FilePath -> IO Config
-loadConfig path = Toml.decodeFileEither configCodec path >>= \case
- Left err -> throwM . FigFrontendException $ tshow err
- Right config -> pure config
-
-websocket :: ByteString -> (WS.Connection -> IO ()) -> Sc.ScottyM ()
-websocket pat h = Sc.middleware $ Wai.WS.websocketsOr WS.defaultConnectionOptions handler
- where
- handler pending = if WS.requestPath (WS.pendingRequest pending) == pat
- then WS.acceptRequest pending >>= h
- else WS.rejectRequest pending ""