Skip to content
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

docs: jsdocs for the server functions #438

Merged
merged 3 commits into from
May 7, 2024
Merged
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
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
Loading