@logotip4ik_/nuxt-cloudflare-headers
v1.3.3
Published
[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href]
Downloads
39
Readme
☁ Nuxt3 Cloudflare Headers
Cloudflare headers Module for Nuxt3
Features
- 👌 Easy to use
- ✅ Nuxt3 compatible
- 🧾 Supports static generation
Setup
- Add
@logotip4ik_/nuxt-cloudflare-headers
dependency to your project
yarn add @logotip4ik_/nuxt-cloudflare-headers # or npm install @logotip4ik_/nuxt-cloudflare-headers
- Add
@logotip4ik_/nuxt-cloudflare-headers
to themodules
section ofnuxt.config.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:
// nuxt.config.js
import { defineNuxtConfig } from "nuxt";
import cloudflareHeaders from "@logotip4ik_/nuxt-cloudflare-headers";
export default defineNuxtConfig({
modules: [cloudflareHeaders],
cloudflareHeaders: {
"/*": { "some-cool": "header" },
},
});
Documentation
// 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:
/*
some-cool: header
hello: world
/admin
! some-cool
For more features read cloudflare docs about
_headers
file
Development
- Clone this repository
- Run
npm run dev:prepare
to generate type stubs. - Use
npm run dev
to start playground in development mode.