# Gateways

A gateway is an always available cloud load balancer or WEB server with flexible traffic processing policies.

![gateways-main](/en/assets/images/main-19b8b7724c36ce8fe4c771d5447f65ea.png)

## Overview

You can reserve your own or use a domain in the tuna.am zone and create a gateway for this domain. Gateway descriptions use [traffic policies](https://tuna.am/en/docs/traffic-policy.md). After saving, the settings will be applied and requests will start being processed by the node to which the domain and accordingly the gateway is assigned.

## When is this useful?

Tunnels are great, but sometimes the environment consists of several services, some of which are running on your machine, on your colleague's machine, and in a test environment. But thanks to flexible [traffic policies](https://tuna.am/en/docs/traffic-policy.md) you can distribute requests to the right points, manage headers, authorization, working hours, and much more.

## How to create a Gateway?

1. Reserve a domain in the [domains section](https://my.tuna.am/domains) that you plan to use, for this article's example it will be `demo.stage.tuna.am`
2. Go to the [Gateways section](https://my.tuna.am/gateways) and click **Add gateway**, select the previously reserved domain.
3. Describe the policy using [traffic policies](https://tuna.am/en/docs/traffic-policy.md) syntax and click **Create**.

If the syntax is correct, the gateway will be immediately available and you can start working.

## Example

Imagine a demo stand available only on weekdays, the main part of which is in a test environment, and 2 microservices are behind developers' tunnels.

```yaml
rules:
  - expressions:
      - now().Weekday().String() in ["Saturday", "Sunday"]
    actions:
      - type: custom_response
        config:
          statusCode: 200
          content: We don't work on weekends!
          headers:
            content-type: "text/plain; charset=utf-8"
  - expressions:
      - hasPrefix(req.URL.Path, "/admin")
    actions:
     - type: reverse_proxy
       config:
         url: "https://valera-dev.run.tuna.am"
  - expressions:
      - hasPrefix(req.URL.Path, "/checkout")
    actions:
     - type: reverse_proxy
       config:
         url: "https://alena-dev.run.tuna.am"
  - actions:
     - type: reverse_proxy
       config:
         url: "https://testing.example.com"

```

So on weekends you will get the message `We don't work on weekends!`, and on weekdays all main requests will go to the test environment at `https://testing.example.com`, everything behind `/admin` will go to the tunnel `https://valera-dev.run.tuna.am`, and `/checkout` to `https://alena-dev.run.tuna.am`.
