HTTPS only
This commit is contained in:
+4
-1
@@ -45,7 +45,10 @@ import Data.Ranged.Ranges (emptyRange)
|
||||
|
||||
data AppConfig = AppConfig {
|
||||
configDbUri :: String
|
||||
, configPort :: Int }
|
||||
, configPort :: Int
|
||||
, configSslCert :: FilePath
|
||||
, configSslKey :: FilePath
|
||||
}
|
||||
|
||||
jsonContentType :: (HeaderName, BS.ByteString)
|
||||
jsonContentType = (hContentType, "application/json")
|
||||
|
||||
+9
-1
@@ -9,6 +9,7 @@ import Database.HDBC.PostgreSQL (connectPostgreSQL')
|
||||
|
||||
import Control.Applicative
|
||||
import Options.Applicative hiding (columns)
|
||||
import Network.Wai.Handler.WarpTLS (tlsSettings, runTLS)
|
||||
|
||||
-- }}}
|
||||
|
||||
@@ -18,6 +19,10 @@ argParser = AppConfig
|
||||
<> help "database uri to expose, e.g. postgres://user:pass@host:port/database")
|
||||
<*> option (long "port" <> short 'p' <> metavar "NUMBER" <> value 3000
|
||||
<> help "port number on which to run HTTP server")
|
||||
<*> strOption (long "sslcert" <> short 'c' <> metavar "PATH" <> value "test/test.crt"
|
||||
<> help "path to SSL cert file")
|
||||
<*> strOption (long "sslkey" <> short 'k' <> metavar "PATH" <> value "test/test.key"
|
||||
<> help "path to SSL key file")
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
@@ -25,9 +30,12 @@ main = do
|
||||
let port = configPort conf
|
||||
let dburi = configDbUri conf
|
||||
|
||||
let tls = tlsSettings (configSslCert conf) (configSslKey conf)
|
||||
let settings = setPort port defaultSettings
|
||||
|
||||
Prelude.putStrLn $ "Listening on port " ++ (show $ configPort conf :: String)
|
||||
conn <- connectPostgreSQL' dburi
|
||||
run port $ app conn
|
||||
runTLS tls settings $ app conn
|
||||
|
||||
where
|
||||
describe = progDesc "create a REST API to an existing Postgres database"
|
||||
|
||||
Reference in New Issue
Block a user