Ability to set addresses to listen on

Fixes #461
This commit is contained in:
Jacky Hu
2016-06-18 10:46:02 +08:00
parent c1764c4976
commit e571cb9fcb
4 changed files with 16 additions and 4 deletions
+1
View File
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Ability to generate an OpenAPI spec - @mainx07, @hudayou, @ruslantalpa, @begriffs
- Ability to set addresses to listen on - @hudayou
### Fixed
- Do not apply limit to parent items - @ruslantalpa
+5 -2
View File
@@ -13,6 +13,7 @@ import PostgREST.DbStructure
import Control.Monad
import Data.Monoid ((<>))
import Data.String.Conversions (cs)
import Data.String (IsString (..))
import qualified Hasql.Query as H
import qualified Hasql.Session as H
import qualified Hasql.Decoders as HD
@@ -47,9 +48,11 @@ main = do
hSetBuffering stderr NoBuffering
conf <- readOptions
let port = configPort conf
let host = configHost conf
port = configPort conf
pgSettings = cs (configDatabase conf)
appSettings = setPort port
appSettings = setHost (fromString host)
. setPort port
. setServerName (cs $ "postgrest/" <> prettyVersion)
$ defaultSettings
+1 -1
View File
@@ -52,7 +52,7 @@ argParser = AppConfig
<$> argument str (help "(REQUIRED) database connection string, e.g. postgres://user:pass@host:port/db" <> metavar "DB_URL")
<*> strOption (long "anonymous" <> short 'a' <> help "(REQUIRED) postgres role to use for non-authenticated requests" <> metavar "ROLE")
<*> strOption (long "schema" <> short 's' <> help "schema to use for API routes" <> metavar "NAME" <> value "public" <> showDefault)
<*> strOption (long "hostname" <> short 'n' <> help "hostname on which the HTTP server is running" <> metavar "HOSTNAME" <> value "localhost" <> showDefault)
<*> strOption (long "host" <> short 'l' <> help "hostname or ip on which to run HTTP server" <> metavar "HOST" <> value "*4" <> showDefault)
<*> option auto (long "port" <> short 'p' <> help "port number on which to run HTTP server" <> metavar "PORT" <> value 3000 <> showDefault)
<*> (secret . cs <$>
strOption (long "jwt-secret" <> short 'j' <> help "secret used to encrypt and decrypt JWT tokens" <> metavar "SECRET" <> value "secret" <> showDefault))
+9 -1
View File
@@ -215,6 +215,14 @@ makeRootPathItem = ("/", p)
makePathItems :: [(Table, [Column], [Text])] -> InsOrdHashMap FilePath PathItem
makePathItems ti = fromList $ makeRootPathItem : map makePathItem ti
escapeHostName :: String -> String
escapeHostName "*" = "0.0.0.0"
escapeHostName "*4" = "0.0.0.0"
escapeHostName "!4" = "0.0.0.0"
escapeHostName "*6" = "0.0.0.0"
escapeHostName "!6" = "0.0.0.0"
escapeHostName h = h
postgrestSpec:: [(Table, [Column], [Text])] -> String -> Integer -> Swagger
postgrestSpec ti h p = (mempty :: Swagger)
& basePath ?~ "/"
@@ -227,7 +235,7 @@ postgrestSpec ti h p = (mempty :: Swagger)
& definitions .~ makeDefinitions ti
& paths .~ makePathItems ti
where
h' = Just $ Host h (Just (fromInteger p))
h' = Just $ Host (escapeHostName h) (Just (fromInteger p))
encodeOpenAPI :: [(Table, [Column], [Text])] -> String -> Integer -> ByteString
encodeOpenAPI ti h p = encode $ postgrestSpec ti h p