---
title: Proxy
project: Total.js V5
version: 0.0.20
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v5/0-0-20/reference/proxy/
updated: 2026-11-18T16:57:34.578Z
---

# Proxy

> PROXYSERVER() and PROXYCLIENT().

## API

### PROXYSERVER([endpoint], [socketendpoint], [logger])

Type: `method` · Since: `0.0.17`

Forwards HTTP requests to a proxy client connected over a WebSocket.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `endpoint` | `String` | no | `'/'` | Path prefix of the requests to forward. |
| `socketendpoint` | `String` | no | `'/'` | Path of the WebSocket route for the client. |
| `logger` | `Function` | no | `console with a date` | Called as `logger(status, message)` when the client connects or disconnects. |

Registers `PROXY(endpoint)` for all requests except WebSocket ones and a binary WebSocket route at `socketendpoint` (messages up to 100 MB) for the client started with `PROXYCLIENT()`. Each request is sent to the client with its method, URL, headers, IP and body, and the response of the client is streamed back.

Only one client can be connected; a second one closes the first with code `4001` and is not used, so connect the client again. Without a client, requests get `400` with `Not yet available.`. Choose a `socketendpoint` that does not collide with your routes. When the request to the local app fails (the app does not run or closes the connection), the visitor gets an empty response with the status `200`.

Example: Public server
```js
exports.install = function() {
	PROXYSERVER('/', '/$proxy/');
};
```

### PROXYCLIENT(proxyserver, target, [logger])

Type: `method` · Since: `0.0.17`

Connects a local HTTP server to a `PROXYSERVER()` and answers its requests.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `proxyserver` | `String` | yes |  | URL of the WebSocket endpoint of `PROXYSERVER()`. |
| `target` | `String` | yes |  | Local server as `'ip:port'` or `'port'`. |
| `logger` | `Function` | no | `console with a date` | Called with the status and a message on connect, disconnect and each request. |

Returns: `WebSocketClient` The client connection.

Opens a binary WebSocket to `proxyserver` (an `http`/`https` URL is changed to `ws`/`wss`). Every request that arrives is made against the local server `target` with the original method, path, headers and body, plus the header `x-proxy: Total.js` and the `host` of the target. The response is streamed back.

`target` is `'ip:port'` or only a port (then `127.0.0.1` is used). The function returns the WebSocket client; it returns nothing and prints its usage when an argument is missing.

Example: Publish a local app
```js
PROXYCLIENT('https://public.example.com/$proxy/', '8000');
```

Example: Quiet
```js
PROXYCLIENT('https://public.example.com/$proxy/', '192.168.1.10:8000', NOOP);
```
