Skip to content

Commit 282e61a

Browse files
committed
External ws port
1 parent 16184fb commit 282e61a

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

src/Client/Im/WebSocket/WebSocket.js

-3
This file was deleted.
+4-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
module Client.Im.WebSocket where
22

33
import Prelude
4-
import Shared.Im.Types (WebSocketPayloadServer)
54

65
import Client.Common.Location as CCD
76
import Effect (Effect)
8-
import Effect.Uncurried (EffectFn3)
9-
import Effect.Uncurried as EU
107
import Environment (production)
8+
import Shared.Im.Types (WebSocketPayloadServer)
119
import Shared.Json as SJ
12-
import Shared.Options.WebSocket (port)
10+
import Shared.Options.WebSocket (externalPort, localPort)
1311
import Web.Socket.WebSocket (WebSocket)
1412
import Web.Socket.WebSocket as WSWS
1513

16-
foreign import closeWith_ EffectFn3 WebSocket Int String Unit
17-
1814
createWebSocket Effect WebSocket
1915
createWebSocket = do
2016
hostName ← CCD.hostName
@@ -24,11 +20,8 @@ createWebSocket = do
2420
| production = "wss://"
2521
| otherwise = "ws://"
2622
endpoint
27-
| production = "/ws"
28-
| otherwise = ":" <> show port
23+
| production = "/ws:" <> show externalPort
24+
| otherwise = ":" <> show localPort
2925

3026
sendPayload WebSocket WebSocketPayloadServer Effect Unit
3127
sendPayload ws = WSWS.sendString ws <<< SJ.toJson
32-
33-
closeWith WebSocket Int String Effect Unit
34-
closeWith = EU.runEffectFn3 closeWith_

src/Server/Admin/Action.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Prelude
44

55
import Debug (spy)
66
import Effect.Class (liftEffect)
7-
import Environment (production)
7+
88
import Run.Reader as RR
99
import Server.Response as SR
1010
import Server.Token as ST
@@ -13,15 +13,15 @@ import Server.WebSocket (WebSocketMessage(..))
1313
import Server.WebSocket as SW
1414
import Shared.Im.Types (WebSocketPayloadServer(..))
1515
import Shared.Json as SJ
16-
import Shared.Options.WebSocket (port)
16+
import Shared.Options.WebSocket (localPort)
1717

1818
ban Int { id Int, secret String } ServerEffect Unit
1919
ban loggedUserId query = do
2020
{ configuration: { adminSecret } } ← RR.ask
2121
if query.secret == adminSecret then do
2222
cookie ← ST.createToken loggedUserId
2323
liftEffect do
24-
connection ← SW.createWebSocket ("ws://localhost:" <> show port) cookie
24+
connection ← SW.createWebSocket ("ws://localhost:" <> show localPort) cookie
2525
SW.onOpen connection $ \_ → SW.sendMessage connection <<< WebSocketMessage <<< SJ.toJson $ Ban query
2626
else
2727
SR.throwBadRequest "nope"

src/Server/Main.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Server.WebSocket (Port(..))
1919
import Server.WebSocket as SW
2020
import Server.WebSocket.Events (aliveDelay, inactiveDelay)
2121
import Server.WebSocket.Events as SWE
22-
import Shared.Options.WebSocket (port)
22+
import Shared.Options.WebSocket (localPort)
2323
import Shared.Spec (spec)
2424

2525
main Effect Unit
@@ -31,7 +31,7 @@ main = do
3131
startWebSocketServer Configuration Effect Unit
3232
startWebSocketServer configuration = do
3333
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)
3535
SW.onServerError webSocketServer SWE.handleError
3636
pool ← SD.newPool configuration
3737
SW.onConnection webSocketServer (SWE.handleConnection configuration pool allUsersAvailabilityRef)

src/Shared/Options/WebSocket.purs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module Shared.Options.WebSocket where
22

3-
port Int
4-
port = 1339
3+
localPort Int
4+
localPort = 1339
5+
6+
externalPort Int
7+
externalPort = 1443

0 commit comments

Comments
 (0)