interceptor.lua 498 B

123456789101112131415161718
  1. require "website"
  2. function access()
  3. if string.sub(request:filepath(),1,12) == "/api/public/" then
  4. --公共开放接口
  5. return true
  6. elseif string.sub(request:filepath(),1,11) == "/api/admin/" then
  7. --管理员目录,需要验证权限
  8. print(param("key"),"\t")
  9. if param("key") == nil or param("key") ~= "123456" then
  10. response:send("key不正确")
  11. return false
  12. end
  13. return true
  14. else
  15. response:send("仅允许访问 /api/public 和 /api/admin 目录")
  16. return false
  17. end
  18. end