Skip to content

Commit

Permalink
Merge pull request HapticX#374 from HapticX/dev
Browse files Browse the repository at this point in the history
improve server speed
  • Loading branch information
Ethosa authored Nov 16, 2024
2 parents 8d583fd + 4952817 commit 3b1d08a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/happyx/ssr/server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,14 @@ macro routes*(server: Server, body: untyped = newStmtList()): untyped =
body.handleLiveViews()

when enableHttpx or enableHttpBeast or enableBuiltin:
var path = newCall("decodeUrl", newNimNode(nnkBracketExpr).add(
newCall("split", newCall("get", newCall("path", ident"req")), newLit('?')),
newLit(0)
))
var path =
when enableBuiltin:
newCall("decodeUrl", ident"urlPath")
else:
newCall("decodeUrl", newNimNode(nnkBracketExpr).add(
newCall("split", newCall("get", newCall("path", ident"req")), newLit('?')),
newLit(0)
))
let
reqMethod = newCall("get", newDotExpr(ident"req", ident"httpMethod"))
hostname = newDotExpr(ident"req", ident"ip")
Expand All @@ -812,17 +816,21 @@ macro routes*(server: Server, body: untyped = newStmtList()): untyped =
), newLit(0)
)
val = ident(fmt"_val")
url = newStmtList(
newLetStmt(val, newCall("split", newCall("get", newCall("path", ident"req")), newLit"?")),
newNimNode(nnkIfStmt).add(
newNimNode(nnkElifBranch).add(
newCall(">=", newCall("len", val), newLit(2)),
newNimNode(nnkBracketExpr).add(val, newLit(1))
), newNimNode(nnkElse).add(
newLit("")
url =
when enableBuiltin:
ident"queryRaw"
else:
newStmtList(
newLetStmt(val, newCall("split", ident"urlPath", newLit"?")),
newNimNode(nnkIfStmt).add(
newNimNode(nnkElifBranch).add(
newCall(">=", newCall("len", val), newLit(2)),
newNimNode(nnkBracketExpr).add(val, newLit(1))
), newNimNode(nnkElse).add(
newLit("")
)
)
)
)
)
else:
var path = newCall("decodeUrl", newDotExpr(newDotExpr(ident"req", ident"url"), ident"path"))
let
Expand Down

0 comments on commit 3b1d08a

Please sign in to comment.