# Services

Source: https://tiltas.openpanel.sh/docs/services

> Give a program on a Device its own name, such as http://gitea, and choose who may open it.

A **Service** is something running on a Device that your Network reaches by its own name. Opening a Service to someone
opens that one program and nothing else on the Device. There are two kinds:

- **Web**: a website or web app, opened in a browser at `http://gitea`. This page creates one.
- **TCP**: a database or any other program that wants an address, such as `postgres:5432`. See
  [TCP Services](/docs/services/tcp).

> Diagram: a browser on an allowed Device opens http://gitea. The Device that hosts the Service checks who is asking, then passes the request to the target, such as localhost:3000. Nothing else on that Device is opened.

The Device that hosts the Service serves it itself, so traffic goes straight from the visitor's Device to it, encrypted
end to end. How it works is in [Services](/docs/concepts/services).

## Create a Web Service

You need a program that answers HTTP on a Device in your Network, for example Gitea on port 3000 of the Server `home`.

### Open Services

In the [console](/app), open **Services** and choose **Create Service**.

### Describe it

- **Kind**: **Web**.
- **Runs on**: the Device the program runs on, such as `home`.
- **Service name**: lowercase letters, digits and dashes, such as `gitea`. Devices and Services share one list of names,
  so a Service cannot be called like a Device.
- **Target on home**: where the program listens, as seen from that Device, such as `localhost:3000`. A Web Service's
  target always has a port. What else it may be: [What a target can be](/docs/services/targets).

### Choose who can open it

Under **Who can open it**, keep **Everyone in the Network** or pick Members, Groups and Devices. Everyone else is
refused, even other programs on the same Device. With nobody chosen, the Service stays closed.

Turn on **Tell the program who is asking** if the program should learn who opened it: see
[Identity headers](/docs/services/identity-headers).

### Create it

Choose **Create Service**. The hosting Device picks up the change within seconds.

From any Device that is allowed, at home or on mobile data, open:

```text title="Address" noCopy
http://gitea
```

The longer name `http://gitea.<your Network domain>`, such as `http://gitea.zukai.ql.internal`, works too. The program
receives the name the visitor used in the `Host` header.

**http:// inside your Network is still encrypted**

Between two Devices, every packet travels inside WireGuard, so `http://gitea` is not readable on the way. HTTPS names
for Web Services, for browsers that insist on HTTPS, are built but not switched on yet: see
[HTTPS for Web Services](/docs/services/https).

## What a visitor may see

| The visitor sees | Why |
|---|---|
| **No Service here** (404) | No Service on that Device has this name. The page names no other Service. |
| **Not allowed** (403) | The visitor's Device is not in **Who can open it**. |
| **Service unreachable** (502) | The hosting Device could not reach the target: the program is down, or the target is an address it may not reach. |

## Change or delete a Service

In **Services**, open the menu at the end of a row:

- **Edit** and **Change who can open it** open the Service's form: its name, target, ports, **Tell the program who is
  asking** and who can open it. Its kind and the Device it runs on stay as they are; to change those, create a new
  Service.
- **Delete** stops the Service answering at once, for everyone, and removes its Access rule. The program on the Device
  keeps running.

Removing a Device from the Network deletes its Services too.

## Who can create Services

A Member can add Services to their own Personal devices. Owners and Admins can add, change and delete Services on any
Device. [Roles](/docs/people/roles) lists the rest.

## With the API

The same Service, created with an [Access token](/docs/api):

```bash
curl -X POST https://tiltas.openpanel.sh/api/v1/accounts/acc_your_account/services \
  -H "Authorization: Bearer $TILTAS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "gitea", "kind": "web", "device_id": "dev_your_device", "target": "localhost:3000", "allowed": {"everyone": true}}'
```

Without `allowed`, a Service made with an Access token stays closed until you choose who may open it. Every field is in
the [API reference](/docs/api/services/createService).
