From d74bd1c5aeee7195308db0cf543b3352965bd178 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Fri, 2 May 2025 06:30:44 -0600 Subject: [PATCH] Document server.resources --- docs/technical-details/reference/globals.md | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/technical-details/reference/globals.md b/docs/technical-details/reference/globals.md index 2eb4515..795bc2d 100644 --- a/docs/technical-details/reference/globals.md +++ b/docs/technical-details/reference/globals.md @@ -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` -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). \ No newline at end of file +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'); +``` \ No newline at end of file