123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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 function handle_options(fd, header)
- local response_header = {
- ['Access-Control-Allow-Origin'] = '*',
- ['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS, PUT, DELETE',
- ['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization',
- ['Access-Control-Allow-Credentials'] = 'true',
- ['Content-Length'] = '0'
- }
-
- local content = ""
- local ok, err = httpd.write_response(sockethelper.writefunc(fd), 200, response_header, content)
- return ok
- end
- local dispatch = function(session, address,id, addr,...)
- socket.start(id)
- local req= tools.read_request(id)
- if req.url == nil or #req.url==0 or req.code~=200 or #req.body==0 then
- skynet.error(req.url)
- skynet.error("错误访问:")
- tools.dump({address=address,id=id,addr=addr,other=...})
- return tools.response(id, req.code, "error!")
- end
- -- 处理 OPTIONS 请求
- -- if req.method == "OPTIONS" then
- -- handle_options(id,req.header)
- -- socket.close(id)
- -- return tools.response(id, req.code, "error!")
- -- end
- if string.find(req.url, "tg/back/") then
- local func_list = string.split(req.url ,"/")
- skynet.send("backmgr","lua","on_recv",id,func_list[#func_list],req.body)
- return
- end
- end
- skynet.start(function()
- skynet.dispatch("lua", dispatch)
- end)
|