You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Global-sales/wai-server/middleware/components/forward.middleware.js

25 lines
869 B
JavaScript

const { domain } = require('../../config').server;
const { isEmpty } = require('../../utils/commons.util');
const { getConnection } = require('../../services/connections.service');
const axios = require('axios');
module.exports = async (ctx, next) => {
try {
console.log('forward start ---------------');
// console.log(/^\/wai-server\/v\d{1}\/(?!channels|messages)/.test(ctx.path));
const { waisession } = ctx.headers;
if (isEmpty(waisession)) {
await next();
} else {
const findSession = await getConnection({ sesson_id: waisession, connect_domain: domain });
if (!isEmpty(findSession)) {
// todo: 设置一个flag, 是否存在, 不用再查一遍
await next();
}
}
// todo: forward to target server
console.log('forward End ---------------');
} catch (err) {}
};