Skip to content

Commit

Permalink
fix: 프록시 서버 https 넘기기
Browse files Browse the repository at this point in the history
  • Loading branch information
sjy2335 committed Nov 14, 2024
1 parent af708fc commit 8d5f1c9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion backend/proxy-server/src/server/proxy-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class ProxyServer {
connections: Number(process.env.DEFAULT_CONNECTIONS),
pipelining: Number(process.env.DEFAULT_PIPELINING),
keepAliveTimeout: Number(process.env.DEFAULT_KEEP_ALIVE),
connect: {
rejectUnauthorized: false,
},
},
});
}
Expand Down Expand Up @@ -89,7 +92,7 @@ export class ProxyServer {
private async executeProxyRequest(request: FastifyRequest, reply: FastifyReply): Promise<void> {
const host = validateHost(request.headers[HOST_HEADER]);
const ip = await this.resolveDomain(host);
const targetUrl = buildTargetUrl(ip, request.url, 'http://'); // TODO: Protocol 별 arg 세팅
const targetUrl = buildTargetUrl(ip, request.url, 'https://'); // TODO: Protocol 별 arg 세팅

await this.sendProxyRequest(targetUrl, request, reply);
}
Expand All @@ -114,6 +117,8 @@ export class ProxyServer {
request: FastifyRequest,
reply: FastifyReply,
): Promise<void> {
const originalHost = request.headers[HOST_HEADER] as string;

await new Promise<void>((resolve, reject) => {
reply.from(targetUrl, {
onError: (reply, error) => {
Expand All @@ -125,6 +130,11 @@ export class ProxyServer {
),
);
},

rewriteRequestHeaders: (req, headers) => ({
...headers,
host: originalHost,
}),
});
});
}
Expand Down

0 comments on commit 8d5f1c9

Please sign in to comment.