Skip to content

Commit

Permalink
Merge pull request #346 from HapticX/dev
Browse files Browse the repository at this point in the history
little server update
  • Loading branch information
Ethosa authored Sep 21, 2024
2 parents 8af28de + 8fe2c08 commit cfd717e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/happyx/ssr/server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1264,12 +1264,15 @@ macro routes*(server: Server, body: untyped = newStmtList()): untyped =
else:
newEmptyNode(),
procStmt,
newProc(
ident"finalizeProgram",
[newEmptyNode()],
finalize,
pragmas = newNimNode(nnkPragma).add(ident"noconv")
)
if finalize.len > 0:
newProc(
ident"finalizeProgram",
[newEmptyNode()],
finalize,
pragmas = newNimNode(nnkPragma).add(ident"noconv")
)
else:
newEmptyNode()
)

for v in countdown(variables.len-1, 0, 1):
Expand Down Expand Up @@ -1320,7 +1323,10 @@ macro initServer*(body: untyped): untyped =
ident"main",
[newEmptyNode()],
body.add(
newCall("addQuitProc", ident"finalizeProgram")
newNimNode(nnkWhenStmt).add(newNimNode(nnkElifBranch).add(
newCall("declared", ident"finalizeProgram"),
newCall("addQuitProc", ident"finalizeProgram"),
))
),
nnkProcDef
),
Expand Down Expand Up @@ -1388,7 +1394,10 @@ macro serve*(address: string, port: int, body: untyped): untyped =
newEmptyNode(),
newCall("routes", s, body),
newCall("start", s),
newCall("addQuitProc", ident"finalizeProgram")
newNimNode(nnkWhenStmt).add(newNimNode(nnkElifBranch).add(
newCall("declared", ident"finalizeProgram"),
newCall("addQuitProc", ident"finalizeProgram"),
))
),
nnkProcDef
),
Expand Down
13 changes: 13 additions & 0 deletions tests/testc21.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import
../src/happyx


serve "127.0.0.1", 5000:
get "/":
""
get "/user/$id":
id
post "/user":
""
notfound:
"method not allowed"

0 comments on commit cfd717e

Please sign in to comment.