Skip to content

Commit

Permalink
docs: jsdocs for the server functions (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlexLichter authored May 7, 2024
1 parent dd6cfc0 commit c796e1f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ export interface StorageServerOptions {
resolvePath?: (event: H3Event) => string;
}

/**
* This function creates an h3-based handler for the storage server. It can then be used as event handler in h3 or Nitro
* @param storage The storage which should be used for the storage server
* @param opts Storage options to set the authorization check or a custom path resolver
* @returns
* @see createStorageServer if a node-compatible handler is needed
*/
export function createH3StorageHandler(
storage: Storage,

opts: StorageServerOptions = {}
): EventHandler {
return eventHandler(async (event) => {
Expand Down Expand Up @@ -143,6 +149,22 @@ export function createH3StorageHandler(
});
}

/**
* This function creates a node-compatible handler for your custom storage server.
*
* The storage server will handle HEAD, GET, PUT and DELETE requests.
* HEAD: Return if the request item exists in the storage, including a last-modified header if the storage supports it and the meta is stored
* GET: Return the item if it exists
* PUT: Sets the item
* DELETE: Removes the item (or clears the whole storage if the base key was used)
*
* If the request sets the `Accept` header to `application/octet-stream`, the server will handle the item as raw data.
*
* @param storage The storage which should be used for the storage server
* @param options Defining functions such as an authorization check and a custom path resolver
* @returns An object containing then `handle` function for the handler
* @see createH3StorageHandler For the bare h3 version which can be used with h3 or Nitro
*/
export function createStorageServer(
storage: Storage,
options: StorageServerOptions = {}
Expand Down

0 comments on commit c796e1f

Please sign in to comment.