Commit 282e61a 1 parent 16184fb commit 282e61a Copy full SHA for 282e61a
File tree 5 files changed +14
-21
lines changed
5 files changed +14
-21
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
module Client.Im.WebSocket where
2
2
3
3
import Prelude
4
- import Shared.Im.Types (WebSocketPayloadServer )
5
4
6
5
import Client.Common.Location as CCD
7
6
import Effect (Effect )
8
- import Effect.Uncurried (EffectFn3 )
9
- import Effect.Uncurried as EU
10
7
import Environment (production )
8
+ import Shared.Im.Types (WebSocketPayloadServer )
11
9
import Shared.Json as SJ
12
- import Shared.Options.WebSocket (port )
10
+ import Shared.Options.WebSocket (externalPort , localPort )
13
11
import Web.Socket.WebSocket (WebSocket )
14
12
import Web.Socket.WebSocket as WSWS
15
13
16
- foreign import closeWith_ ∷ EffectFn3 WebSocket Int String Unit
17
-
18
14
createWebSocket ∷ Effect WebSocket
19
15
createWebSocket = do
20
16
hostName ← CCD .hostName
@@ -24,11 +20,8 @@ createWebSocket = do
24
20
| production = " wss://"
25
21
| otherwise = " ws://"
26
22
endpoint
27
- | production = " /ws"
28
- | otherwise = " :" <> show port
23
+ | production = " /ws: " <> show externalPort
24
+ | otherwise = " :" <> show localPort
29
25
30
26
sendPayload ∷ WebSocket → WebSocketPayloadServer → Effect Unit
31
27
sendPayload ws = WSWS .sendString ws <<< SJ .toJson
32
-
33
- closeWith ∷ WebSocket → Int → String → Effect Unit
34
- closeWith = EU .runEffectFn3 closeWith_
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import Prelude
4
4
5
5
import Debug (spy )
6
6
import Effect.Class (liftEffect )
7
- import Environment ( production )
7
+
8
8
import Run.Reader as RR
9
9
import Server.Response as SR
10
10
import Server.Token as ST
@@ -13,15 +13,15 @@ import Server.WebSocket (WebSocketMessage(..))
13
13
import Server.WebSocket as SW
14
14
import Shared.Im.Types (WebSocketPayloadServer (..))
15
15
import Shared.Json as SJ
16
- import Shared.Options.WebSocket (port )
16
+ import Shared.Options.WebSocket (localPort )
17
17
18
18
ban ∷ Int → { id ∷ Int , secret ∷ String } → ServerEffect Unit
19
19
ban loggedUserId query = do
20
20
{ configuration: { adminSecret } } ← RR .ask
21
21
if query.secret == adminSecret then do
22
22
cookie ← ST .createToken loggedUserId
23
23
liftEffect do
24
- connection ← SW .createWebSocket (" ws://localhost:" <> show port ) cookie
24
+ connection ← SW .createWebSocket (" ws://localhost:" <> show localPort ) cookie
25
25
SW .onOpen connection $ \_ → SW .sendMessage connection <<< WebSocketMessage <<< SJ .toJson $ Ban query
26
26
else
27
27
SR .throwBadRequest " nope"
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import Server.WebSocket (Port(..))
19
19
import Server.WebSocket as SW
20
20
import Server.WebSocket.Events (aliveDelay , inactiveDelay )
21
21
import Server.WebSocket.Events as SWE
22
- import Shared.Options.WebSocket (port )
22
+ import Shared.Options.WebSocket (localPort )
23
23
import Shared.Spec (spec )
24
24
25
25
main ∷ Effect Unit
@@ -31,7 +31,7 @@ main = do
31
31
startWebSocketServer ∷ Configuration → Effect Unit
32
32
startWebSocketServer configuration = do
33
33
allUsersAvailabilityRef ← ER .new DH .empty
34
- webSocketServer ← SW .createWebSocketServerWithPort (Port port ) {} $ const (EC .log $ " Web socket now up on ws://localhost:" <> show port )
34
+ webSocketServer ← SW .createWebSocketServerWithPort (Port localPort ) {} $ const (EC .log $ " Web socket now up on ws://localhost:" <> show localPort )
35
35
SW .onServerError webSocketServer SWE .handleError
36
36
pool ← SD .newPool configuration
37
37
SW .onConnection webSocketServer (SWE .handleConnection configuration pool allUsersAvailabilityRef)
Original file line number Diff line number Diff line change 1
1
module Shared.Options.WebSocket where
2
2
3
- port ∷ Int
4
- port = 1339
3
+ localPort ∷ Int
4
+ localPort = 1339
5
+
6
+ externalPort ∷ Int
7
+ externalPort = 1443
You can’t perform that action at this time.
0 commit comments