From 44626aace914db058de4273a276a564aeb66b51e Mon Sep 17 00:00:00 2001 From: Lucy Cifferello Date: Wed, 12 Aug 2020 16:19:58 -0600 Subject: [PATCH] add configurable setting to enable running app for tor --- config/settings.yml | 1 + src/Application.hs | 12 +++++++----- src/Settings.hs | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/config/settings.yml b/config/settings.yml index 7cda8fe..e3cd492 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -32,6 +32,7 @@ app-compatibility-path: "_env:APP_COMPATIBILITY_CONFIG:/etc/start9/registry/comp resources-path: "_env:RESOURCES_PATH:/var/www/html/resources" ssl-path: "_env:SSL_PATH:/var/ssl" registry-hostname: "_env:REGISTRY_HOSTNAME:registry.start9labs.com" +enable-tor: "false" database: database: "_env:PG_DATABASE:start9_registry" diff --git a/src/Application.hs b/src/Application.hs index 17c3008..1356645 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -34,7 +34,7 @@ import Database.Persist.Postgresql (createPostgresqlPool, pg import Language.Haskell.TH.Syntax (qLocation) import Network.Wai import Network.Wai.Handler.Warp (Settings, defaultSettings, defaultShouldDisplayException, - getPort, setHost, setOnException, setPort) + getPort, setHost, setOnException, setPort, run) import Network.Wai.Handler.WarpTLS import Network.Wai.Middleware.AcceptOverride import Network.Wai.Middleware.Autohead @@ -202,10 +202,12 @@ startWeb foundation = do startWeb' app = do let AppSettings{..} = appSettings foundation putStrLn @Text $ "Launching Web Server on port " <> show appPort - action <- async $ runTLS - (tlsSettings sslCertLocation sslKeyLocation) - (warpSettings foundation) - app + action <- async $ if enableTor + then run (fromIntegral appPort) app + else runTLS + (tlsSettings sslCertLocation sslKeyLocation) + (warpSettings foundation) + app setWebProcessThreadId (asyncThreadId action) foundation void $ waitCatch action diff --git a/src/Settings.hs b/src/Settings.hs index d37148f..17645a5 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -53,6 +53,7 @@ data AppSettings = AppSettings , sslKeyLocation :: FilePath , sslCsrLocation :: FilePath , sslCertLocation :: FilePath + , enableTor :: Bool } instance FromJSON AppSettings where @@ -67,6 +68,7 @@ instance FromJSON AppSettings where resourcesDir <- o .: "resources-path" sslPath <- o .: "ssl-path" registryHostname <- o .: "registry-hostname" + enableTor <- o .: "enable-tor" let sslKeyLocation = sslPath "key.pem" let sslCsrLocation = sslPath "certificate.csr"