https://github.com/sukkaw/kv4cf
A Modified version of cloudflare/kv-asset-handler, with Non-ASCII URL supported.
https://github.com/sukkaw/kv4cf
cloudflare cloudflare-kv cloudflare-workers
Last synced: 5 months ago
JSON representation
A Modified version of cloudflare/kv-asset-handler, with Non-ASCII URL supported.
- Host: GitHub
- URL: https://github.com/sukkaw/kv4cf
- Owner: SukkaW
- License: mit
- Created: 2020-06-06T09:56:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-02T16:42:29.000Z (over 5 years ago)
- Last Synced: 2025-09-20T04:36:46.531Z (5 months ago)
- Topics: cloudflare, cloudflare-kv, cloudflare-workers
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kv4cf
A modified version of [`@cloudflare/kv-asset-handler`](https://www.npmjs.com/package/@cloudflare/kv-asset-handler).
[](https://www.npmjs.com/package/kv4cf)  
## 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
```bash
# @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](https://www.npmjs.com/package/@cloudflare/kv-asset-handler).
Only a few differences need to be noticed:
### Use CommonJS instead of ESModule
```javascript
// 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
```javascript
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](https://github.com/SukkaW), Released under the [MIT](./LICENSE) License.
> [Personal Website](https://skk.moe) · [Blog](https://blog.skk.moe) · GitHub [@SukkaW](https://github.com/SukkaW) · Telegram Channel [@SukkaChannel](https://t.me/SukkaChannel) · Twitter [@isukkaw](https://twitter.com/isukkaw) · Keybase [@sukka](https://keybase.io/sukka)