Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/logotip4ik/unplugin-cloudflare-headers

Generate ☁cloudflare headers
https://github.com/logotip4ik/unplugin-cloudflare-headers

Last synced: 16 days ago
JSON representation

Generate ☁cloudflare headers

Awesome Lists containing this project

README

        

# unplugin-cloudflare-headers

[![NPM version](https://img.shields.io/npm/v/unplugin-cloudflare-headers?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-cloudflare-headers)

## Install

```bash
npm i unplugin-cloudflare-headers
```

## Usage

Vite

```ts
// vite.config.ts
import CloudflareHeaders from 'unplugin-cloudflare-headers/vite'

export default defineConfig({
plugins: [
CloudflareHeaders({ /* options */ }),
],
})
```

Rollup

```ts
// rollup.config.js
import CloudflareHeaders from 'unplugin-cloudflare-headers/rollup'

export default {
plugins: [
CloudflareHeaders({ /* options */ }),
],
}
```


Webpack

```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-cloudflare-headers/webpack')({ /* options */ })
]
}
```


esbuild

```ts
// esbuild.config.js
import { build } from 'esbuild'
import CloudflareHeaders from 'unplugin-cloudflare-headers/esbuild'

build({
plugins: [CloudflareHeaders()],
})
```


## Options

Top level keys of the options are route definitions. Each route should have an array of headers. Header is simple object, where key is header name and value (`string` or `false`) is header value. Let's see example.

This options:
```js
const options = {
'/*': [{ 'x-testing': 'hello 🌐' }],
'/admin': [{ 'x-testing': false }]
// use `false` as header value to detach header from specific route
}
```

will result into this `_headers` file:

```text
/*
x-testing: hello 🌐
/admin
! x-testing
```

More on `_headers` file in [cloudflare docs](https://developers.cloudflare.com/pages/platform/headers)

License [MIT](./LICENSE)