@zarfjs/adapter-cf-worker
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@zarfjs/adapter-cf-worker

Cloudflare worker adapter for Zarf. Provide a Zarf app, and let this adapter adapt the incoming requests and outgoing responses into a format Cloudflare understands.

Usage


Basic

import { Zarf } from '@zarfjs/zarf'
import { createFetchAdapter } from '@zarfjs/adapter-cf-worker'

const app = new Zarf()

app.get("/hello/:user", (ctx, params) => {
    return ctx.json({
        user: params.user
    })
})

export default {
    fetch: createFetchAdapter(app)
};

Static

import { Zarf } from '@zarfjs/zarf'
import { createStaticFetchAdapter } from '@zarfjs/adapter-cf-worker/static'

const app = new Zarf()

app.get("/hello/:user", (ctx, params) => {
    return ctx.json({
        user: params.user
    })
})

export default {
    fetch: createStaticFetchAdapter(app, {
        cors: true, // wanna enable CORS for all assets to all?
    })
};

For detailed example refer example

Author


Aftab Alam https://github.com/one-aalam

License


Distributed under the MIT License. See LICENSE for more information.

Package Sidebar

Install

npm i @zarfjs/adapter-cf-worker

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

11.1 kB

Total Files

9

Last publish

Collaborators

  • one-aalam