Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

Auto generate cloudflare headers with Nuxt3
https://github.com/logotip4ik/nuxt-cloudflare-headers

cloudflare headers nuxt3

Last synced: 2 days ago
JSON representation

Auto generate cloudflare headers with Nuxt3

Awesome Lists containing this project

README

        

# โ˜ Nuxt3 Cloudflare Headers

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]

> Cloudflare headers Module for Nuxt3

[๐Ÿ“– **Release Notes**](https://github.com/logotip4ik/nuxt-cloudflare-headers/releases)

## Features

- ๐Ÿ‘Œ Easy to use
- โœ… Nuxt3 compatible
- ๐Ÿงพ Supports static generation

## Setup

1. Add `@logotip4ik_/nuxt-cloudflare-headers` dependency to your project

```bash
yarn add @logotip4ik_/nuxt-cloudflare-headers # or npm install @logotip4ik_/nuxt-cloudflare-headers
```

2. Add `@logotip4ik_/nuxt-cloudflare-headers` to the `modules` section of `nuxt.config.js`

```js
// nuxt.config.js
import { defineNuxtConfig } from "nuxt";
import cloudflareHeaders from "@logotip4ik_/nuxt-cloudflare-headers";

export default defineNuxtConfig({
modules: [
// With inlined options
[cloudflareHeaders, { "/api": { "x-powered-by": "cloudflare" } }],
],
});
```

Or a separate section `nuxt-cloudflare-headers` for module options:

```js
// nuxt.config.js
import { defineNuxtConfig } from "nuxt";
import cloudflareHeaders from "@logotip4ik_/nuxt-cloudflare-headers";

export default defineNuxtConfig({
modules: [cloudflareHeaders],

cloudflareHeaders: {
"/*": { "some-cool": "header" },
},
});
```

## Documentation

```js
// nuxt.config.js
import { defineNuxtConfig } from "nuxt";
import cloudflareHeaders from "@logotip4ik_/nuxt-cloudflare-headers";

export default defineNuxtConfig({
modules: [cloudflareHeaders],

cloudflareHeaders: {
"/*": { "some-cool": "header", "hello": "world" },
"/admin": { "some-cool": false }, // detaching `some-cool` header from admin route
},
});
```

In `cloudflareHeaders` object key (`/*`, `/admin`) will be route matcher and array of objects or plain object will be actual header rules. Where `some-cool` will be header name and `header` will be header value. Also you can detach a header from route by providing `false` as value. So if you are generating your project with such a config, nuxt will prerender `_headers` file with this content inside:

```text
/*
some-cool: header
hello: world

/admin
! some-cool
```

> For more features read [cloudflare docs about `_headers` file](https://developers.cloudflare.com/pages/platform/headers)

## Development

1. Clone this repository
2. Run `npm run dev:prepare` to generate type stubs.
3. Use `npm run dev` to start [playground](./playground) in development mode.

## License

[MIT License](./LICENSE)

[npm-version-src]: https://img.shields.io/npm/v/@logotip4ik_/nuxt-cloudflare-headers/latest.svg
[npm-version-href]: https://npmjs.com/package/@logotip4ik_/nuxt-cloudflare-headers
[npm-downloads-src]: https://img.shields.io/npm/dt/@logotip4ik_/nuxt-cloudflare-headers.svg
[npm-downloads-href]: https://npmjs.com/package/@logotip4ik_/nuxt-cloudflare-headers