Skip to content

Document server.resources #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release_4.5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion docs/technical-details/reference/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,24 @@ This records the provided value as a metric into Harper's analytics. Harper effi
This returns the user object with permissions/authorization information based on the provided username. This does not verify the password, so it is generally used for looking up users by username. If you want to verify a user by password, use [`server.authenticateUser`](globals.md#serverauthenticateuserusername-password-user).

### `server.authenticateUser(username, password): Promise<User>`
This returns the user object with permissions/authorization information based on the provided username. The password will be verified before returning the user object (if the password is incorrect, an error will be thrown).
This returns the user object with permissions/authorization information based on the provided username. The password will be verified before returning the user object (if the password is incorrect, an error will be thrown).

### `server.resources: Resources`
This provides access to the map of all registered resources. This is the central registry in Harper for registering any resources to be exported for use by REST, MQTT, or other components. Components that want to register resources should use the `server.resources.set(name, resource)` method to add to this map. Exported resources can be found by passing in a path to `server.resources.getMatch(path)` which will find any resource that matches the path or beginning of the path.

#### `server.resources.set(name, resource, exportTypes?)`
Register a resource with the server. For example:
```
class NewResource extends Resource {
}
server.resources.set('NewResource', Resource);
// or limit usage:
server.resources.set('NewResource', Resource, { rest: true, mqtt: false, 'my-protocol': true });
```
#### `server.resources.getMatch(path, exportType?)`
Find a resource that matches the path. For example:
```
server.resources.getMatch('/NewResource/some-id');
// or specify the export/protocol type, to allow it to be limited:
server.resources.getMatch('/NewResource/some-id', 'my-protocol');
```