# Server

## Content

# Class: Server

Represents a collaboration server, provides bidirectional communication, middleware and hooks mechanism.

## Table of contents

### Constructors

- [constructor](Server#constructor)

### Properties

- [licenseKey](Server#licensekey)

### Methods

- [on](Server#on)
- [use](Server#use)
- [useFeature](Server#usefeature)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new Server**(`config?`)

#### Parameters

| Name | Type |
| :------ | :------ |
| `config?` | [`IServerConfig`](../interfaces/IServerConfig) |

## Properties

### <a id="licensekey" name="licensekey"></a> licenseKey

• **licenseKey**: `string`

License key for server validation and collaboration features.

## Methods

### <a id="on" name="on"></a> on

▸ **on**(`hooks`): `void`

Registers multiple hooks to the server in a batch.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `hooks` | [`IHooks`](../interfaces/IHooks) | The hooks to register. |

#### Returns

`void`

▸ **on**<`K`\>(`action`, `hook`): `void`

Registers a single hook for a specific action on the server.

#### Type parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `K` | extends keyof [`IHookContext`](../interfaces/IHookContext) | Type of the action name, extending keyof IHookContext. |

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `action` | `K` | he name of the action to associate with the hook |
| `hook` | [`IHook`](../interfaces/IHook)<[`IHookContext`](../interfaces/IHookContext)[`K`]\> | The hook to register for the specified action. |

#### Returns

`void`

___

### <a id="use" name="use"></a> use

▸ **use**(`middlewares`): `void`

Registers multiple middlewares to the server in a batch.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `middlewares` | [`IMiddlewares`](../interfaces/IMiddlewares) | The middlewares to register. |

#### Returns

`void`

▸ **use**<`K`\>(`action`, `middleware`): `void`

Registers a single middleware for a specific action on the server.

#### Type parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `K` | extends keyof [`IMiddlewareContext`](../interfaces/IMiddlewareContext) | Type of the action name, extending keyof IMiddlewareContext. |

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `action` | `K` | The name of the action to associate with the middleware. |
| `middleware` | [`IMiddleware`](../interfaces/IMiddleware)<[`IMiddlewareContext`](../interfaces/IMiddlewareContext)[`K`]\> | The middleware to register for the specified action. |

#### Returns

`void`

___

### <a id="usefeature" name="usefeature"></a> useFeature

▸ **useFeature**(`feature`): `void`

Register feature to the server.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `feature` | [`IFeature`](../interfaces/IFeature) | The feature to register. |

#### Returns

`void`
