JavaScript를 사용하여 Azure Functions를 빌드하고 개발 프록시를 사용하려는 경우 Node.js 애플리케이션에서 개발 프록시를 사용하기 위한 일반적인 지침을 따릅니다.
중요합니다
Azure Functions가 시작 시 실패하지 않도록 하려면 --as-system-proxy false 옵션을 사용하거나, asSystemProxy을 false로 파일 devproxyrc.json에서 구성하여 개발자 프록시를 시스템 프록시로 등록하지 않고 시작하십시오. 개발자 프록시를 시스템 프록시로 등록하면 Azure Functions가 시작 시 다음과 유사한 오류 메시지와 함께 실패합니다.
Grpc.Core.RpcException: 'Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while unable to establish HTTP/2 connection.", DebugException="System.Net.Http.HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while unable to establish HTTP/2 connection.")'
개발에서 개발 프록시를 사용하고 프로덕션 환경에서 사용하지 않는 것 간에 쉽게 전환할 수 있도록 환경 변수를 사용하여 Azure Functions 앱에서 프록시를 구성하는 것이 가장 좋습니다. 환경 변수 local.settings.json을(를) 포함하도록 HTTPS_PROXY 파일을 변경합니다. 또한 Azure Functions 앱이 개발자 프록시에서 사용하는 자체 서명된 인증서를 신뢰할 수 있도록 인증서 유효성 검사를 사용하지 않도록 설정합니다.
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"HTTPS_PROXY": "http://127.0.0.1:8000",
"NODE_TLS_REJECT_UNAUTHORIZED": "0"
}
}
Azure Functions 앱에서 개체를 process.env 사용하여 환경 변수를 읽고 HTTP 요청에 대한 프록시를 구성합니다.
import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";
import fetch from 'node-fetch';
import { HttpsProxyAgent } from 'https-proxy-agent';
export async function MyFnHttpTrigger(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
const options = process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {};
const resp = await fetch('https://jsonplaceholder.typicode.com/posts', options);
const data = await resp.json();
return {
status: 200,
jsonBody: data
};
};
app.http('MyFnHttpTrigger', {
methods: ['GET', 'POST'],
authLevel: 'anonymous',
handler: MyFnHttpTrigger
});
Dev Proxy