# Domain Proxy

이 가이드에서는 소유하고 있는 도메인을 통해 프록시 서버를 설정하고 Hackle SDK와 함께 사용하는 방법을 설명합니다.\
이는 광고차단(Ad block) 프로그램이 사용자 행동 추적에 미치는 영향을 줄이는데 유용합니다.

![](/files/Yl1TAj0Pxt7y1iaOr83x)

프록시 서버를 설정하고 적용하려면 아래 두단계를 설정해야 합니다.

1. **프록시 서버 설정**
2. **SDK에서 프록시 서버를 가리키도록 설정**

***

## 1. 프록시 서버 설정

#### 클라우드를 통한 설정

대부분의 주요 클라우드 제공업체는 프록시 서비스를 쉽게 개발하고 배포할 수 있습니다.

아래는 AWS CloudFront 를 이용한 프록시 서비스를 설정하는 예시입니다.

* [AWS CloudFront Console](https://us-east-1.console.aws.amazon.com/cloudfront) 접속
* Create distribution 클릭
* Origin 영역
  * Origin domain: `event.hackle.io` 설정
  * Protocol: `HTTPS Only` 설정

![](/files/FsLNOGcY04YPGphoF4tW)

* Default cache behavior 영역
  * Viewer protocol policy: `Redirect HTTP to HTTPS` 설정
  * Allowed HTTP methods: `GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE` 설정
  * Cache key and origin requests: 모든 Header와 Parameter가 Origin으로 전달되도록 허용하고 Origin에 대한 CORS 요청을 허용합니다.

![](/files/x1KfEBkSuIGVWFhAQjv3)

* In Function associations 영역
  * Origin request: `Host` 헤더를 `event.hackle.io` 로 변경하기 위해 Lambda\@Edge Function 을 추가합니다.\
    참고: [Tutorial: Creating a simple Lambda@Edge function](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-how-it-works-tutorial.html)

![](/files/VPM8lJQT6szsLMOpC3GW)

아래 코드를 Lambda\@Edge Function 에서 사용합니다.

```javascript
export const handler = (event, context, callback) => {
  const request = event.Records[0].cf.request;
  request.headers.host[0].value = 'event.hackle.io';
  return callback(null, request);
};
```

* 화면 하단 Create distribution 클릭

#### 프록시 서버 구축

프록시 서버를 직접 구축할 수도 있습니다.

[NGINX를 이용한 프록시 서버 구축 예시](https://github.com/hackle-io/hackle-event-proxy)입니다. 아래 설정은 프록시 서버에 대한 모든 호출을 Hackle로 리디렉션합니다.

```
events {}
http {
    server {
        listen 80;
        listen [::]:80;

        location / {
            proxy_set_header Host event.hackle.io;
            proxy_set_header X-Real-IP $http_x_forwarded_for;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host $server_name;
            proxy_pass https://event.hackle.io/;
        }
    }
}
```

## 2. SDK 설정

SDK에서 프록시 서버를 가리키도록 설정해야 합니다. SDK 초기화시 `eventUrl`옵션을 통해 설정할 수 있습니다.

```javascript
const config = {
  eventUrl: "https://<YOUR_PROXY_DOMAIN>"
};

createInstance(YOUR_SDK_KEY, config);
```

```java
HackleConfig config = HackleConfig.builder()
  .eventUri("https://<YOUR_PROXY_DOMAIN>")
  .build();

HackleApp.initializeApp(getApplicationContext(), YOUR_SDK_KEY, config)
```

```swift
let config = HackleConfigBuilder()
  .eventUrl(URL(string: "https://<YOUR_PROXY_DOMAIN>")!)
  .build()

Hackle.initialize(sdkKey: YOUR_SDK_KEY, config: config)
```

```javascript
HackleConfig config = HackleConfigBuilder()
  .eventUrl("https://<YOUR_PROXY_DOMAIN>")
  .build();

await HackleApp.initialize(YOUR_SDK_KEY, hackleConfig: config);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/development-guide/troubleshooting/domain-proxy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
