kv4cf

0.1.0 • Public • Published

cloudflare-kv-handler

A Modified version of @cloudflare/kv-asset-handler, with Non-ASCII URL supported.

Installation

npm uninstall @cloudflare/kv-asset-handler
npm install kv4cf

Usage

Nearly exactly the same as @cloudflare/kv-asset-handler, so please refer to its README.

Only a few differences need to be noticed:

Use CommonJS instead of ESModule

// What you should do to import @cloudflare/kv-asset-handler
import { getAssetFromKV } from '@cloudflare/kv-asset-handler'
 
// What you should do to import kv4cf
const { getAssetFromKV } = require('kv4cf');

Custom Error handling

const { getAssetFromKV } = require('kv4cf');
const { NotFoundError, MethodNotAllowedError, InternalError } = require('kv4cf/lib/error');
 
addEventListener('fetch', event => {
  event.respondWith(handleEvent(event))
})
 
async function handleEvent(event) {
  try {
    return await getAssetFromKV(event)
  } catch (e) {
    if (instanceof NotFoundError) {
      // ...
    } else if (instanceof MethodNotAllowedError) {
      // ...
    } else if (instanceof InternalError) {
      // ...
    } else {
      // ...
    }
  }
}

Package Sidebar

Install

npm i kv4cf

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

10.7 kB

Total Files

4

Last publish

Collaborators

  • sukkaw