# ServerProxyEvent events

> 2 FeatherPanel plugin events on ServerProxyEvent (2 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/server-proxy/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions.

## Setup

Import `ServerProxyEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\ServerProxyEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ServerProxyEvent::onServerProxyCreated(), function ($userUuid, $serverUuid, $proxyId, $domain, $port): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:server:proxy:create ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'proxy_id' => $proxyId, 'domain' => $domain, 'port' => $port]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `ServerProxyEvent::onServerProxyCreated()`

- Name: `featherpanel:server:proxy:create`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerProxyEvent.php#L27)

Docblock: string user uuid, string server uuid, int|null proxy id, string domain, int port.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `server_uuid` | `$serverUuid` | `string`from docblock |
| 3 | `proxy_id` | `$proxyId` | `int|null`from docblock |
| 4 | `domain` | `$domain` | `string`from docblock |
| 5 | `port` | `$port` | `int` |

When it fires (1 site)

-   [`ServerProxyController::createProxy`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/ServerProxyController.php#L298) via `emitEvent()`[`POST /api/user/servers/{uuidShort}/proxy/create`](https://featherpanel.com/docs/api/reference/user/server/proxy/#post-user-servers-uuidShort-proxy-create)

```php
$event->on(ServerProxyEvent::onServerProxyCreated(), function ($userUuid, $serverUuid, $proxyId, $domain, $port): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:server:proxy:create ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'proxy_id' => $proxyId, 'domain' => $domain, 'port' => $port]));
});
```

## `ServerProxyEvent::onServerProxyDeleted()`

- Name: `featherpanel:server:proxy:delete`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerProxyEvent.php#L35)

Docblock: string user uuid, string server uuid, int|null proxy id, string domain, int port.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `server_uuid` | `$serverUuid` | `string`from docblock |
| 3 | `proxy_id` | `$proxyId` | `int` |
| 4 | `domain` | `$domain` | `string`from docblock |
| 5 | `port` | `$port` | `int` |

When it fires (1 site)

-   [`ServerProxyController::deleteProxy`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/ServerProxyController.php#L446) via `emitEvent()`[`POST /api/user/servers/{uuidShort}/proxy/delete`](https://featherpanel.com/docs/api/reference/user/server/proxy/#post-user-servers-uuidShort-proxy-delete)

```php
$event->on(ServerProxyEvent::onServerProxyDeleted(), function ($userUuid, $serverUuid, $proxyId, $domain, $port): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:server:proxy:delete ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'proxy_id' => $proxyId, 'domain' => $domain, 'port' => $port]));
});
```
