웹프록시 환경에소 오류 발생시 필요한 옵션

이 글은 2024-08-19에 최종 업데이트 되었습니다.

Table of contents

만약 클라이언트의 인터넷 접속이 웹프록시를 거치는 환경이라면, 플러그인을 테스트 할 때 아래와 같은 오류가 발생할 수 있습니다.

1
2
3
4
5
6
7
8
9
10
11
12
FetchError: request to https://login.botframework.com/v1/.well-known/openidconfiguration failed, reason: self-signed certificate in certificate chain
    at ClientRequest.<anonymous> (C:\Users\10038305\TeamsApps\plugin001\node_modules\node-fetch\lib\index.js:1501:11)
    at ClientRequest.emit (node:events:517:28)
    at TLSSocket.socketErrorListener (node:_http_client:501:9)
    at TLSSocket.emit (node:events:517:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'SELF_SIGNED_CERT_IN_CHAIN',
  code: 'SELF_SIGNED_CERT_IN_CHAIN'
}

이 이슈는 봇프레임웍과 통신하는 과정에서 웹프록시가 자체 인증서로 변경한 것을 이유로 웹 앱이 응답을 차단하기 때문에 발생합니다. 예외적인 아래의 옵션을 추가하여 이슈를 회피할 수 있습니다.

process.env.NODE_TLS_REJECT_UNAUTHORIZED = ‘0’;


현재 테스트 중인 프로젝트의 기준으로는 searchApp.js 파일에 넣어주면 됩니다. (11 라인) 아래는 search.app.js 파일의 앞부분입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const axios = require("axios");
const querystring = require("querystring");
const { TeamsActivityHandler, CardFactory } = require("botbuilder");
const ACData = require("adaptivecards-templating");
const helloWorldCard = require("./adaptiveCards/helloWorldCard.json");
const pokemonCard = require("./adaptiveCards/pokemonCard.json");
const { Console } = require("console");
const { type } = require("os");

// 환경변수로 node에서 허가되지 않은 인증TLS통신을 거부하지 않겠다고 설정
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

function search(nameKey, myArray, returnVal){
  for (let i=0; i < myArray.length; i++) {
      if (myArray[i].name === nameKey) {
        if (returnVal){
          return myArray[i].value;
        }
        else{
          return myArray[i];
        }
      }
  }
}