@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Ability to generate an OpenAPI spec - @mainx07, @hudayou, @ruslantalpa, @begriffs
|
- Ability to generate an OpenAPI spec - @mainx07, @hudayou, @ruslantalpa, @begriffs
|
||||||
|
- Ability to set addresses to listen on - @hudayou
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Do not apply limit to parent items - @ruslantalpa
|
- Do not apply limit to parent items - @ruslantalpa
|
||||||
|
|||||||
+5
-2
@@ -13,6 +13,7 @@ import PostgREST.DbStructure
|
|||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
import Data.String.Conversions (cs)
|
import Data.String.Conversions (cs)
|
||||||
|
import Data.String (IsString (..))
|
||||||
import qualified Hasql.Query as H
|
import qualified Hasql.Query as H
|
||||||
import qualified Hasql.Session as H
|
import qualified Hasql.Session as H
|
||||||
import qualified Hasql.Decoders as HD
|
import qualified Hasql.Decoders as HD
|
||||||
@@ -47,9 +48,11 @@ main = do
|
|||||||
hSetBuffering stderr NoBuffering
|
hSetBuffering stderr NoBuffering
|
||||||
|
|
||||||
conf <- readOptions
|
conf <- readOptions
|
||||||
let port = configPort conf
|
let host = configHost conf
|
||||||
|
port = configPort conf
|
||||||
pgSettings = cs (configDatabase conf)
|
pgSettings = cs (configDatabase conf)
|
||||||
appSettings = setPort port
|
appSettings = setHost (fromString host)
|
||||||
|
. setPort port
|
||||||
. setServerName (cs $ "postgrest/" <> prettyVersion)
|
. setServerName (cs $ "postgrest/" <> prettyVersion)
|
||||||
$ defaultSettings
|
$ defaultSettings
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ argParser = AppConfig
|
|||||||
<$> argument str (help "(REQUIRED) database connection string, e.g. postgres://user:pass@host:port/db" <> metavar "DB_URL")
|
<$> 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 "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 "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)
|
<*> option auto (long "port" <> short 'p' <> help "port number on which to run HTTP server" <> metavar "PORT" <> value 3000 <> showDefault)
|
||||||
<*> (secret . cs <$>
|
<*> (secret . cs <$>
|
||||||
strOption (long "jwt-secret" <> short 'j' <> help "secret used to encrypt and decrypt JWT tokens" <> metavar "SECRET" <> value "secret" <> showDefault))
|
strOption (long "jwt-secret" <> short 'j' <> help "secret used to encrypt and decrypt JWT tokens" <> metavar "SECRET" <> value "secret" <> showDefault))
|
||||||
|
|||||||
@@ -215,6 +215,14 @@ makeRootPathItem = ("/", p)
|
|||||||
makePathItems :: [(Table, [Column], [Text])] -> InsOrdHashMap FilePath PathItem
|
makePathItems :: [(Table, [Column], [Text])] -> InsOrdHashMap FilePath PathItem
|
||||||
makePathItems ti = fromList $ makeRootPathItem : map makePathItem ti
|
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:: [(Table, [Column], [Text])] -> String -> Integer -> Swagger
|
||||||
postgrestSpec ti h p = (mempty :: Swagger)
|
postgrestSpec ti h p = (mempty :: Swagger)
|
||||||
& basePath ?~ "/"
|
& basePath ?~ "/"
|
||||||
@@ -227,7 +235,7 @@ postgrestSpec ti h p = (mempty :: Swagger)
|
|||||||
& definitions .~ makeDefinitions ti
|
& definitions .~ makeDefinitions ti
|
||||||
& paths .~ makePathItems ti
|
& paths .~ makePathItems ti
|
||||||
where
|
where
|
||||||
h' = Just $ Host h (Just (fromInteger p))
|
h' = Just $ Host (escapeHostName h) (Just (fromInteger p))
|
||||||
|
|
||||||
encodeOpenAPI :: [(Table, [Column], [Text])] -> String -> Integer -> ByteString
|
encodeOpenAPI :: [(Table, [Column], [Text])] -> String -> Integer -> ByteString
|
||||||
encodeOpenAPI ti h p = encode $ postgrestSpec ti h p
|
encodeOpenAPI ti h p = encode $ postgrestSpec ti h p
|
||||||
|
|||||||
Reference in New Issue
Block a user