serverconf.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --- Algernon Server Configuration
  2. --- For use with the samples
  3. --- Logging (will log to console if an empty string is given)
  4. --LogTo("algernon.log")
  5. --LogTo("/var/log/algernon.log")
  6. --- Clear the URL prefixes for the access permissions
  7. --- (see https://github.com/xyproto/permissions2 for an overview of the default paths)
  8. ClearPermissions()
  9. --- For the "bob" example, when running from this directory
  10. AddAdminPrefix("/samples/bob/admin")
  11. AddUserPrefix("/samples/bob/data")
  12. --- For the "bob" example, when running from the "bob" directory
  13. AddAdminPrefix("/admin")
  14. AddUserPrefix("/data")
  15. --- For the "chat" example, when running from this directory
  16. AddUserPrefix("/samples/chat/chat")
  17. --- For the "chat" example, when running from the "chat" directory
  18. AddUserPrefix("/chat")
  19. --- Reverse proxy examples
  20. AddReverseProxy("/api/", "http://localhost:8080")
  21. AddReverseProxy("/api/auth", "http://localhost:8100")
  22. -- Output server configuration after parsing this file and commandline arguments
  23. OnReady(function ()
  24. print(ServerInfo())
  25. end)
  26. -- Custom permission denied handler
  27. DenyHandler(function ()
  28. content("text/html")
  29. print[[<!doctype html><html><head><title>Permission denied</title><link href='//fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'></head><body style="background-color: #f0f0f0; color: #101010; font-family: 'Lato', sans-serif; font-weight: 300; margin: 4em; font-size: 2em;">]]
  30. print("<strong>HTTP "..method()..[[</strong> <font color="red">denied</font> for ]]..urlpath().." (based on the current permission settings).")
  31. print([[</body></html>]])
  32. end)
  33. -- Global configuration
  34. fields = {
  35. sitename = "Sample Site",
  36. }
  37. -- Store global variables as Lua code in the database.
  38. -- Any other Lua file may load them with: CodeLib():import("globals")
  39. OnReady(function()
  40. -- Prepare a CodeLib object and clear the "globals" key
  41. codelib = CodeLib()
  42. -- Store the configuration strings as Lua code under the key "globals".
  43. local first = true
  44. for k, v in pairs(fields) do
  45. luaCode = k .. "=\"" .. v .. "\""
  46. if first then
  47. codelib:set("globals", luaCode)
  48. first = false
  49. else
  50. codelib:add("globals", luaCode)
  51. end
  52. end
  53. print(codelib:get("globals"))
  54. --SetCookieSecret("asdfasdf")
  55. --print("Cookie secret = " .. CookieSecret())
  56. end)