init.lua 987 B

12345678910111213141516171819202122232425262728
  1. local skynet = require "skynet"
  2. -- local httpc = require "http.httpc"
  3. -- local httpurl = require "http.url"
  4. -- local dns = require "skynet.dns"
  5. local httpd = require "http.httpd"
  6. local sockethelper = require "http.sockethelper"
  7. local socket = require "skynet.socket"
  8. local cjson = require "cjson"
  9. local tools = require "tools"
  10. local dispatch = function(session, address,id, addr,...)
  11. socket.start(id)
  12. local req= tools.read_request(id)
  13. if req.url == nil or #req.url==0 or req.code~=200 or #req.body==0 then
  14. skynet.error(req.url)
  15. skynet.error("错误访问:")
  16. tools.dump({address=address,id=id,addr=addr,other=...})
  17. return tools.response(id, req.code, "error!")
  18. end
  19. if string.find(req.url, "tg/back/") then
  20. local func_list = string.split(req.url ,"/")
  21. skynet.send("backmgr","lua","on_recv",id,func_list[#func_list],req.body)
  22. return
  23. end
  24. end
  25. skynet.start(function()
  26. skynet.dispatch("lua", dispatch)
  27. end)