Using the Warp library, the setHost
function will not accept a dynamic String
as a host value, however it will be perfectly happy with a string literal:
> import Network.Wai.Handler.Warp
> apiHost = "0.0.0.0" :: String
> getHost $ setHost (read apiHost) defaultSettings
*** Exception: Prelude.read: no parse
> getHost $ setHost apiHost defaultSettings
<interactive>:16:19: error:
• Couldn't match type ‘[Char]’ with ‘HostPreference’
Expected type: HostPreference
Actual type: String
> getHost $ setHost "0.0.0.0" defaultSettings
Host "0.0.0.0"
All works fine when the value is a string literal, but I couldn't find any way to make it work when it's a string dynamically generated. Which is exactly what I need, because the host value comes from an environment variable.