main.nim 704 B

123456789101112131415161718192021222324252627
  1. # author: Ethosa
  2. # Working with templates.
  3. import akane
  4. proc main = # main proc for gcsafe
  5. var
  6. server = newServer(debug=true)
  7. data: JsonNode = %{
  8. "myvariable": %0,
  9. "can_place": %false
  10. }
  11. server.pages:
  12. equals("/"): # when url is "domain/"
  13. let index = await loadtemplate("index", data)
  14. # all "$(myvariable)" in template file replaces at data["myvariable"]
  15. data["myvariable"] = %(data["myvariable"].num + 1)
  16. if data["myvariable"].num > 3:
  17. data["can_place"] = %true
  18. await request.answer(index)
  19. notfound:
  20. await request.error("<h1 align='center'>Sorry, but page not found :(</h1>")
  21. server.start() # Starts server.
  22. main()