12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- local skynet = require "skynet"
- -- local httpc = require "http.httpc"
- -- local httpurl = require "http.url"
- -- local dns = require "skynet.dns"
- -- local httpd = require "http.httpd"
- -- local sockethelper = require "http.sockethelper"
- local socket = require "skynet.socket"
- local cjson = require "cjson"
- local tools = require "tools"
- local dispatch = function(session, address,id, addr,...)
- socket.start(id)
- local req = tools.read_request(id)
- -- skynet.error('id,',id)
- -- skynet.error('addr,',addr)
- -- skynet.error('url,',req.url)
- -- skynet.error('header,',)
- -- skynet.error('body,',req.body)
- -- local color,text = "red", "hello"
- -- skynet.error("req.url",req.url)
- if string.find(req.url, "/config/") then
- skynet.send("config_mgr","lua","on_recv",id,req.url,req.body)
- return
- end
- if string.find(req.url, "back/") then
- skynet.send("backmgr","lua","on_recv",id,req.url,req.body)
- return
- end
- if req.url == nil or #req.url==0 or req.code~=200 or #req.body==0 then
- skynet.error(req.url)
- return tools.response(id, req.code, "error!")
- end
- if string.find(req.url, "tools/") then
- skynet.send("tools_work","lua","on_recv",id,req.url,req.body)
- elseif string.find(req.url, "public") then
- local token = req.header.token
- local user_data = nil
- skynet.error(" header.token", req.header.token)
- if token~=nil and #token>1 then
- local user_data = tools.tokenDecode(token)
- user_data = cjson.decode(user_data)
- skynet.error("user_data",user_data)
- skynet.send("public_mgr","lua","on_recv",id,req.url,req.body,user_data)
- else
- skynet.send("public_mgr","lua","on_recv",id,req.url,req.body,nil)
- end
- else
- -- local header = cjson.encode(req.header)
- local token = req.header.token
- local user_data = nil
- skynet.error(" header.token", req.header.token)
- if token~=nil and #token>1 then
- local user_data = tools.tokenDecode(token)
- user_data = cjson.decode(user_data)
- skynet.error("user_data",user_data)
- skynet.send("agentmgr","lua","on_recv",id,req.url,req.body,user_data)
- else
- skynet.send("agentmgr","lua","on_recv",id,req.url,req.body,nil)
- end
- end
-
- end
- skynet.start(function()
- skynet.dispatch("lua", dispatch)
- end)
|