Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display an actual TCP port app is bound to #3034

Merged
merged 28 commits into from
Nov 23, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3eb028f
app: quick'n'dirty displaying of bound port
develop7 Nov 1, 2023
eff8e1a
postgrest style
develop7 Nov 1, 2023
f7c5697
create app sockets ourselves
develop7 Nov 3, 2023
41df536
fix leftover errors
develop7 Nov 3, 2023
ab5bc73
cabal: add streaming-commons
develop7 Nov 6, 2023
b47a358
spec: fix tests
develop7 Nov 6, 2023
4e38128
admin: fixed crash in reachMainApp
develop7 Nov 9, 2023
6081cd6
postgrest-style
develop7 Nov 9, 2023
394b894
postgrest-style
develop7 Nov 9, 2023
17306e3
get unix socket runtime check back
develop7 Nov 10, 2023
44075d4
postgrest-style
develop7 Nov 10, 2023
364f2d2
bind then listen
develop7 Nov 13, 2023
759094a
use setPerms from unix-compat
develop7 Nov 14, 2023
95f665f
style
develop7 Nov 14, 2023
50925df
pin unix-compat for warp
develop7 Nov 14, 2023
7d21a49
put Unix specifics to Postgrest.Unix
develop7 Nov 15, 2023
846bf5d
forgot .cabal
develop7 Nov 15, 2023
30495e6
fix windows build
develop7 Nov 15, 2023
93c3953
fix installSignalHandlers stub
develop7 Nov 16, 2023
b09804e
move domain socket avail check to Unix
develop7 Nov 17, 2023
b9642a3
exe: drop network from deps
develop7 Nov 17, 2023
7fe26dc
style
develop7 Nov 17, 2023
e56e857
unpin unix-compat
develop7 Nov 22, 2023
56d524c
Update postgrest.cabal
steve-chavez Nov 22, 2023
9df15e1
Update postgrest.cabal
steve-chavez Nov 22, 2023
77a9345
test/io: test random port assignment
develop7 Nov 23, 2023
904f01d
style
develop7 Nov 23, 2023
bee8c8b
delete outdated comment add CHANGELOG
steve-chavez Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
postgrest style
develop7 committed Nov 23, 2023
commit eff8e1a7a988d3ba0886e14b622bb45dde5a3d4d
14 changes: 7 additions & 7 deletions src/PostgREST/App.hs
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ import Network.Wai.Handler.Warp (defaultSettings, setHost, setPort,
import System.Posix.Types (FileMode)

import qualified Data.HashMap.Strict as HM
import qualified Data.Text as T (unpack)
import qualified Data.Text.Encoding as T
import qualified Data.Text as T (unpack)
import qualified Hasql.Transaction.Sessions as SQL
import qualified Network.Wai as Wai
import qualified Network.Wai.Handler.Warp as Warp
@@ -61,14 +61,14 @@ import PostgREST.SchemaCache (SchemaCache (..))
import PostgREST.SchemaCache.Routine (Routine (..))
import PostgREST.Version (docsVersion, prettyVersion)

import qualified Control.Exception as E
import qualified Data.ByteString.Char8 as BS
import qualified Data.List as L
import qualified Data.Map as Map (fromList)
import qualified Network.HTTP.Types as HTTP
import qualified Network.Socket as Socket
import Protolude hiding (Handler)
import System.TimeIt (timeItT)
import qualified Network.Socket as Socket
import qualified Control.Exception as E

type Handler = ExceptT Error

@@ -103,18 +103,18 @@ run installHandlers maybeRunWithSocket appState = do
case maddr of
Nothing -> panic ("Could not resolve address " <> show configServerHost <> " port " <> show configServerPort)
Just addr -> do
sock <- E.bracketOnError (Socket.openSocket addr) Socket.close $ \sock -> do
sock <- E.bracketOnError (Socket.openSocket addr) Socket.close $ \sock -> do
Socket.bind sock $ Socket.addrAddress addr
pure sock
port <- Socket.socketPort sock
AppState.logWithZTime appState $ "Listening on port " <> show port
Warp.runSettingsSocket (serverSettings conf) sock app
Warp.runSettingsSocket (serverSettings conf) sock app

where
resolveAddress host port = do
let hints = Socket.defaultHints { Socket.addrSocketType = Socket.Stream }
head <$> Socket.getAddrInfo (Just hints) (Just $ T.unpack host) (Just $ show port)


serverSettings :: AppConfig -> Warp.Settings
serverSettings AppConfig{..} =