# Map Remote

> Proxyman의 Map Remote 기능으로 조건에 맞는 HTTP, HTTPS, WebSocket 요청을 localhost나 스테이징 같은 다른 호스트, 포트, 경로로 리디렉션하세요.

## 1. 무엇인가요? {#1-whats-it}

Map Remote 기능(**⌥⌘R**)은 규칙에 따라 HTTP 요청의 대상 서버를 새 서버로 바꿉니다. 클라이언트는 아무 변화가 없는 것처럼 새 서버에서 응답을 받습니다.

Map Remote 기능은 HTTP와 HTTPS 사이의 매핑도 지원합니다.

![Localhost에서 Production, Staging에서 Production으로 매핑하는 규칙과 Regex 규칙이 있는 Proxyman Map Remote 창](https://proxyman.com/docs/assets/proxyman-map-remote-rules.jpg)

_Map Remote 규칙_

> **노트:** HTTP <-> HTTPS 사이에서 매핑할 때는 일반적인 [Map Remote 설정](https://proxyman.com/docs/ko/advanced-features/map-remote#7-common-usages)을 확인하세요.

> **노트:** Proxyman 4.3.0부터 Map Remote 기능으로 WebSocket과 Secure WebSocket을 지원합니다.

## 2. 장점 {#2-benefits}

* 소스 코드를 수정하지 않고, 개발 웹사이트에서 특정 엔드포인트만 프로덕션 엔드포인트로 사용하세요.
* 프로덕션 웹사이트에서 개발 엔드포인트를 사용하세요.
* 특정 요청 URL을 서로 다른 대상으로 보내세요.
* Protocol, Host, Port, Path, Query 같은 요청 구성 요소를 실시간으로 바꾸세요.

> **노트:** 생산성을 높이려면 [Scripting 기능](https://proxyman.com/docs/ko/scripting/script#1-whats-it)을 사용해 간단한 JavaScript 코드로 Map Remote 기능과 같은 결과를 얻을 수 있습니다.
>
> 예를 들어 [프로덕션을 Localhost 서버로 바꾸는 Snippet Code](https://proxyman.com/docs/ko/scripting/snippet-code#change-request-destination-scheme-host-port-path)를 참고하세요.

## 3. GraphQL 요청에서 Map Remote 사용하기 {#3-map-remote-with-graphql-requests}

Proxyman 2.27.0 이상에서는 특정 QueryName으로 GraphQL 요청에 Map Remote 기능을 적용할 수 있습니다. 아래 GraphQL 문서를 참고하세요.

- [GraphQL 요청 디버깅](https://proxyman.com/docs/ko/advanced-features/graphql)

## 4. Scripting으로 Map Remote 대신 사용하기 ✅ {#4-using-scripting-as-map-remote-}

Map Remote 규칙을 설정하기 어렵다면 [Scripting 도구](https://proxyman.com/docs/ko/scripting/script#1-whats-it)로 더 쉽게 설정할 수 있습니다.

Scripting으로 Map Remote 기능과 같은 결과를 얻는 방법은 [Map Remote Snippet Code](https://proxyman.com/docs/ko/scripting/snippet-code#8-map-remote-with-scripting)를 참고하세요.

예를 들어 Scripting으로 다음 작업을 쉽게 할 수 있습니다:

* v1 엔드포인트를 v2 엔드포인트로 매핑
* 프로덕션 요청을 Localhost 대상으로 매핑
* Localhost 요청을 프로덕션으로 매핑
* ...

## 5. 매칭 규칙 {#5-matching-rule}

> **노트:** Proxyman은 2.3.0부터 [정규 표현식](https://developer.apple.com/documentation/foundation/nsregularexpression#1965590)과 Wildcard 매칭을 지원합니다. [Wildcard 및 Regex 사용 방법](https://proxyman.com/docs/ko/basic-features/regex)을 확인하세요.

[와일드카드 또는 정규 표현식](https://proxyman.com/docs/ko/basic-features/regex)을 사용해 매칭 규칙을 정의할 수 있습니다.

매칭된 요청에 대해 Proxyman은 다음을 시도합니다:

* 설정된 경우 Protocol, Host, Port, Path, Query를 교체합니다
* 구성 요소가 비어 있으면 매칭된 요청의 해당 구성 요소는 변경하지 않습니다

![http://localhost:3000/* 요청을 https://httpbin.proxyman.app으로 매핑하는 Proxyman Map Remote 규칙 편집기](https://proxyman.com/docs/assets/proxyman-map-remote-rule-editor.jpg)

_Map Remote 규칙 편집기_

> **노트:**
>
> * 텍스트 필드를 비워 두면 매칭된 요청에서 해당 부분을 변경하지 않습니다
> * Map To 필드에서는 Wildcard 사용이 허용되지 않습니다

### 디버깅 {#debugging}

URL과 일치하는 Map Remote 규칙을 찾으려면 요청의 Summary 탭을 여세요:

1. 요청을 선택하세요
2. **Summary** 탭 -> **Debugging Tools**
3. 매핑된 URL을 확인하세요

### Host 헤더 유지 {#preserve-host-header}

기본적으로 Proxyman은 Map Remote에서 설정한 새 호스트와 일치하도록 Host 헤더를 덮어씁니다. 대부분의 요청이 성공하려면 이 동작이 필요합니다.

원래 Host 헤더를 유지하려면 새 항목을 만들 때 "Preserve Host Header" 체크박스를 선택하세요. Proxyman이 Host 값을 그대로 유지합니다.

## 6. 사용 방법 {#6-how-to-use}

* 선택한 요청을 우클릭하고 **Tools** -> **Map Remote…**을 선택하세요. Proxyman이 선택한 요청에서 필요한 데이터를 자동으로 채웁니다.

![요청으로 Map Remote 규칙 만들기](https://proxyman.com/docs/assets/proxyman-map-remote-context-menu.jpg)

_요청으로 Map Remote 규칙 만들기_

## 7. 자주 쓰는 설정 {#7-common-usages}

### 7.1 Localhost(HTTP)를 프로덕션(HTTPS)으로 매핑 {#71-map-localhost-http-to-production-https}

**결과:**

| 원본 URL                                            | 대상 URL                                          |
| --------------------------------------------------- | ------------------------------------------------- |
| http://localhost:3000                               | https://proxyman.io                               |
| http://localhost:3000/pricing                       | https://proxyman.io/pricing                       |
| http://localhost:3000/v1/user?id=123\&name=proxyman | https://proxyman.io/v1/user?id=123\&name=proxyman |
| **POST** http://localhost:3000/login                | **POST** https://proxyman.io/login                |

### 7.2 프로덕션(HTTPS)을 localhost(HTTP)로 매핑 {#72-map-production-https-to-localhost-http}

| 원본 URL                                          | 대상 URL                                            |
| ------------------------------------------------- | --------------------------------------------------- |
| https://proxyman.io                               | http://localhost:3000                               |
| https://proxyman.io/v1/user?id=123\&name=proxyman | http://localhost:3000/v1/user?id=123\&name=proxyman |
| **POST** https://proxyman.io/login                | **POST** http://localhost:3000/login                |

### 7.3 특정 URL을 다른 호스트로 매핑 {#73-map-certain-url-to-another-host}

* 규칙: **https://proxyman.io/v1/user** (예시)
* **Any**와 **Wildcard** 옵션을 선택하세요
* **Include all subpaths of this URL** 체크를 해제하세요: 체크를 해제하면 다른 하위 경로는 매핑되지 않습니다

**Map To:**

* Protocol: **https**
* Host: 새 호스트 (예: staging.proxyman.io)
* Port: **443** (로컬 포트)
* Path와 Query는 비워 두세요

**결과:**

| 원본 URL                                          | 대상 URL                                                  |
| ------------------------------------------------- | --------------------------------------------------------- |
| https://proxyman.io                               | https://proxyman.io (규칙이 매핑되지 않음)                |
| https://proxyman.io/v2/setting                    | https://proxyman.io/v2/setting (규칙이 매핑되지 않음)     |
| https://proxyman.io/v1/user?id=123\&name=proxyman | https://staging.proxyman.io/v1/user?id=123\&name=proxyman |

### 7.4 localhost의 WebSocket을 프로덕션으로 매핑 {#74-map-websocket-from-localhost-to-production}

| 원본 URL                      | 대상 URL                            |
| ----------------------------- | ----------------------------------- |
| ws://localhost:4000           | wss://ws.postman-echo.com           |
| ws://localhost:4000/websocket | wss://ws.postman-echo.com/websocket |

### 7.5 프로덕션의 WebSocket을 localhost 대상으로 매핑 {#75-map-websocket-from-production-to-localhost}

| 원본 URL                            | 대상 URL                      |
| ----------------------------------- | ----------------------------- |
| wss://ws.postman-echo.com           | ws://localhost:3000           |
| wss://ws.postman-echo.com/websocket | ws://localhost:3000/websocket |

## 더 알아보기 {#learn-more}

* [테스트를 위해 API 엔드포인트를 프로덕션에서 localhost 환경으로 전환하기](https://proxyman.com/posts/2025-01-10-switch-api-endpoint-from-localhost-to-production-environment)
