Commit 10a5885a by v_vjyjiang

d

parent 3c6b84d5
var url = require("url"); var url = require("url");
var System = require("../../base/system"); var System = require("../../base/system");
const chnelapi=System.getObject("api.common.channels") const chnelapi = System.getObject("api.common.channels")
var channelCache = {}
module.exports = function (app) { module.exports = function (app) {
app.all("*",async function(req, res,next){ app.all("*", async function (req, res, next) {
try{ try {
let channel=await chnelapi.getChannels(req.headers["x-forwarded-host"]) let channel = null
if(!channel){ let hostaddr = req.headers["x-forwarded-host"]
if (!channelCache[hostaddr]) {
channel = await chnelapi.getChannels(req.headers["x-forwarded-host"])
channelCache[hostaddr] = channel
} else {
channel = channelCache[hostaddr]
}
if (!channel) {
next() next()
}else{ } else {
let rtn=await chnelapi.channelHandle(channel,req.path+"/"+ req.body.actionType,req.body) let rtn = await chnelapi.channelHandle(channel, req.path + "/" + req.body.actionType, req.body)
if(rtn!=null){ if (rtn != null) {
res.end(JSON.stringify(rtn)); res.end(JSON.stringify(rtn));
}else{ } else {
res.end(JSON.stringify({status:-1,message:"fail"})); res.end(JSON.stringify({ status: -1, message: "fail" }));
} }
} }
}catch(e){ } catch (e) {
console.log(e) console.log(e)
res.end(JSON.stringify({status:-1,message:e})); res.end(JSON.stringify({ status: -1, message: e }));
} }
}) })
app.get('/api/:gname/:qname/:method', function (req, res) { app.get('/api/:gname/:qname/:method', function (req, res) {
// var classPath = req.params["qname"]; // var classPath = req.params["qname"];
var methodName = req.params["method"]; var methodName = req.params["method"];
var gname=req.params["gname"]; var gname = req.params["gname"];
classPath=gname+"."+classPath; classPath = gname + "." + classPath;
var tClientIp = System.get_client_ip(req); var tClientIp = System.get_client_ip(req);
req.clientIp = tClientIp; req.clientIp = tClientIp;
req.uagent= req.headers["user-agent"]; req.uagent = req.headers["user-agent"];
// req.classname=classPath; // req.classname=classPath;
var params = []; var params = [];
...@@ -48,14 +56,14 @@ module.exports = function (app) { ...@@ -48,14 +56,14 @@ module.exports = function (app) {
app.post('/api/:gname/:qname/:method', function (req, res) { app.post('/api/:gname/:qname/:method', function (req, res) {
var classPath = req.params["qname"]; var classPath = req.params["qname"];
var methodName = req.params["method"]; var methodName = req.params["method"];
var gname=req.params["gname"]; var gname = req.params["gname"];
var params = []; var params = [];
classPath=gname+"."+classPath; classPath = gname + "." + classPath;
console.log("===================="); console.log("====================");
console.log(classPath); console.log(classPath);
var tClientIp = System.get_client_ip(req); var tClientIp = System.get_client_ip(req);
req.clientIp = tClientIp; req.clientIp = tClientIp;
req.uagent= req.headers["user-agent"]; req.uagent = req.headers["user-agent"];
// req.classname=classPath; // req.classname=classPath;
params.push(gname); params.push(gname);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment