Replies: 3 comments 4 replies
-
Please use
import happyx
mount Clients:
# will available on /clients/
get "/":
return ""
import
happyx,
mounts/[clients]
serve "127.0.0.1", 5000:
# Mounts
mount "/clients" -> Clients
# Pages
get "/{title:string}":
req.answerHtml render(title)
# Static Files
staticDir "/download" -> "public" |
Beta Was this translation helpful? Give feedback.
1 reply
-
@jerrygzy You can use import happyx
proc renderIndex(data: int): string =
return $data & " default client"
proc renderLogin(data: int): string =
return $data & " login client"
mount Clients:
"/":
renderIndex(someData)
"/login":
renderLogin(someData)
serve "127.0.0.1", 5000:
setup:
var someData = 123123
# Mounts
mount "" -> Clients
# Pages (docs)
get "/{title:string}":
req.answerHtml render(title)
# Static Files
staticDir "/download" -> "public" |
Beta Was this translation helpful? Give feedback.
3 replies
-
OK, Now I found you can directly middleware:
if $req.url != "/": # allow "/"
if $req.url != "/auth": # allow "/auth" [POST] inside default client
if inCookies.hasSession(): # allow inCookies with session, and check session valid
let sid = inCookies["hpxSession"]
if sid in cookies: # session valid, -> routes outside middleware
echo "valid session for user id: ", $cookies[sid]
else: # session is invalid, -> redirect to "/"
echo "redirect to default client"
req.answer(" ", Http302,{"Location": "https://my.website.com/"}.newHttpHeaders)
else: # cookie has no session, return empty
return " "
happy x coding ! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
after some time, I have found two approaches.
method 1
, this method does not use app object, which means, it's hard to pass app object to render function.method 2
, this method use app object, but can only work under [setup:] which does not work with DecoratorNote: for Decorator,
method 1
only apply the last route,method 2
does not workmethod 1
only apply the last routemethod 2
does not workBeta Was this translation helpful? Give feedback.
All reactions