简体   繁体   English

代理中间件的可变身份验证参数

[英]variable auth parameter for proxy-middleware

i tried to secure my ngrok tunnels with name and password but run in some problem on my proxy.我试图用名称和密码保护我的 ngrok 隧道,但在我的代理上遇到了一些问题。 If i try to set the variable for that depended on the header from the request, similiar to the router.如果我尝试根据请求的标头设置变量,类似于路由器。

var optionsLogin = {
logLevel: 'debug',
changeOrigin: true,
target: 'not reachable',
auth: function (proxyRequest, path, req) {
    const endpoint= proxyRequest.headers.endpoint;
    const pwd= await redis.getValue(endpoint.toUpperCase() + _'pwd');
    return endpoint + ':' + pwd;
},
router: async function (proxyRequest, path, req) {
    const endpoint= proxyRequest.headers.endpoint
    const domain = await redis.getValue(endpoint.toUpperCase())
    return 'https://' + domain;
},

}; };

Unlucky this works not out不幸的是,这行不通

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. TypeError [ERR_INVALID_ARG_TYPE]: 第一个参数必须是字符串类型或 Buffer、ArrayBuffer 或 Array 的实例或类似数组的对象。 Received function auth收到功能授权

The docu https://www.npmjs.com/package/http-proxy-middleware gives me no idea what to do.文档https://www.npmjs.com/package/http-proxy-middleware让我不知道该怎么做。

I also tried this我也试过这个

var optionsLogin = {
logLevel: 'debug',
changeOrigin: true,
target: 'not reachable',
router: async function (proxyRequest, path, req) {
    const company = proxyRequest.headers.company
    console.log(company)
    const domain = await redis.getValue(company.toUpperCase())
    return 'https://exampleEndpoint:password@'+ domain;
},

}; };

what seems to go into the wrong direction.什么似乎走向错误的方向。

Can somebody help me with this or has an idea?有人可以帮我解决这个问题或有什么想法吗?

I was able to set the credential when i manipulate the header wihtout the "auth" parameter as follow:当我在没有“auth”参数的情况下操作标头时,我能够设置凭据,如下所示:

var optionsLogin = {
   logLevel: 'debug',
   changeOrigin: true,
   target: 'not reachable',
   router: async function (proxyRequest, path, req) {
      const endpoint = proxyRequest.headers.company
      var auth = "Basic " + new Buffer("exampleEndpoint" + ":" + 
      "password").toString("base64");
      proxyRequest.headers = {...proxyRequest.headers,  'Authorization': auth };
      const domain = await redis.getValue(endpoint.toUpperCase())
      return 'https:// + domain;
   },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM