Skip to content
/ kv4cf Public

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

License

Notifications You must be signed in to change notification settings

SukkaW/kv4cf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kv4cf

A modified version of @cloudflare/kv-asset-handler.

Features

  • Non-ASCII URL supported
  • Correct ETag logic (The implementation of @cloudflare/kv-asset-handler is broken)
  • Better performance for large scale of website

Installation

# @cloudflare/kv-asset-handler go away
npm uninstall @cloudflare/kv-asset-handler
# Say hello to kv4cf
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 (e instanceof NotFoundError) {
      // ...
    } else if (e instanceof MethodNotAllowedError) {
      // ...
    } else if (e instanceof InternalError) {
      // ...
    } else {
      // ...
    }
  }
}

Author

kv4cf © Sukka, Released under the MIT License.

Personal Website · Blog · GitHub @SukkaW · Telegram Channel @SukkaChannel · Twitter @isukkaw · Keybase @sukka

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published