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

add useWss and liveviewWsHost defines #335

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
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
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