Skip to content

Commit

Permalink
Merge pull request #335 from HapticX/dev
Browse files Browse the repository at this point in the history
add useWss and liveviewWsHost defines
  • Loading branch information
Ethosa authored Aug 27, 2024
2 parents 6bbe677 + 3446999 commit a40657e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/happyx/ssr/liveviews/liveviews.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import

const liveViewsCache* = CacheSeq"HappyXLiveViews"

const
useWss* {.booldefine.}: bool = false
liveviewWsHost* {.strdefine.}: string = ""


macro liveview*(body: untyped): untyped =
for statement in body:
Expand All @@ -32,19 +36,27 @@ proc handleLiveViews*(body: NimNode) =
"&",
newCall(
"&",
newCall(
"&",
if liveviewWsHost == "":
newCall(
"&",
newCall(
"&",
newLit("var _sc=new WebSocket(\"ws://"),
newDotExpr(ident"server", ident"address"),
newCall(
"&",
if useWss:
newLit("var _sc=new WebSocket(\"wss://")
else:
newLit("var _sc=new WebSocket(\"ws://"),
newDotExpr(ident"server", ident"address"),
),
newLit":",
),
newLit":",
),
newCall("$", newDotExpr(ident"server", ident"port"))
),
newCall("$", newDotExpr(ident"server", ident"port"))
)
elif useWss:
newLit("var _sc=new WebSocket(\"wss://" & liveviewWsHost)
else:
newLit("var _sc=new WebSocket(\"ws://" & liveviewWsHost),
path
),
newLit("\");")
Expand Down

0 comments on commit a40657e

Please sign in to comment.