mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-22 14:21:34 +03:00
45 lines
1016 B
Haskell
45 lines
1016 B
Haskell
|
{-|
|
||
|
Eyre: Http Server Driver
|
||
|
-}
|
||
|
|
||
|
module Urbit.Vere.Eyre.PortsFile
|
||
|
( Ports(..)
|
||
|
, writePortsFile
|
||
|
, removePortsFile
|
||
|
)
|
||
|
where
|
||
|
|
||
|
import Urbit.Prelude
|
||
|
|
||
|
import System.Directory (doesFileExist, removeFile)
|
||
|
import Urbit.Arvo (Port(unPort))
|
||
|
|
||
|
|
||
|
-- Types -----------------------------------------------------------------------
|
||
|
|
||
|
data Ports = Ports
|
||
|
{ pHttps :: Maybe Port
|
||
|
, pHttp :: Port
|
||
|
, pLoop :: Port
|
||
|
}
|
||
|
deriving (Eq, Ord, Show)
|
||
|
|
||
|
|
||
|
-- Creating and Deleting `.http.ports` files. ----------------------------------
|
||
|
|
||
|
portsFileText :: Ports -> Text
|
||
|
portsFileText Ports {..} = unlines $ catMaybes
|
||
|
[ pHttps <&> \p -> (tshow p <> " secure public")
|
||
|
, Just (tshow (unPort pHttp) <> " insecure public")
|
||
|
, Just (tshow (unPort pLoop) <> " insecure loopback")
|
||
|
]
|
||
|
|
||
|
removePortsFile :: FilePath -> IO ()
|
||
|
removePortsFile pax = do
|
||
|
doesFileExist pax >>= \case
|
||
|
True -> removeFile pax
|
||
|
False -> pure ()
|
||
|
|
||
|
writePortsFile :: FilePath -> Ports -> IO ()
|
||
|
writePortsFile f = writeFile f . encodeUtf8 . portsFileText
|