@jackdbd/hosting-utils
v1.0.0
Published
Utilities for working with the configuration files of various hosting providers.
Downloads
103
Maintainers
Readme
@jackdbd/hosting-utils
Utilities for working with the configuration files of various hosting providers.
Installation
npm install @jackdbd/hosting-utils
Note: this library was tested on Node.js >=18. It might work on other Node.js versions though.
Usage
Let's say that you are hosting your Eleventy site on Vercel and that you want to programmatically add a Content-Security-Policy
header to a bunch of routes. You could do something like this:
import { updateVercelJSON } from '@jackdbd/hosting-utils'
await updateVercelJSON({
headerKey: 'Content-Security-Policy',
headerValue: "default-src 'self'; img-src 'self' cdn.example.com;",
filepath: '_site/vercel.json',
sources: ['/(404|index).html', '/posts/**/*.html']
})
Configuration
Read these resources to understand how to configure _headers
, serve.json
, vercel.json
.
- Attach headers to Cloudflare Pages responses
- serve
- serve-handler options
- Configure headers in
vercel.json
Troubleshooting
This plugin uses the debug library for logging.
You can control what's logged using the DEBUG
environment variable.
For example, if you set your environment variables in a .envrc
file, you can do:
# print all logging statements
export DEBUG=hosting-utils:*
Dependencies
| Package | Version |
|---|---|
| netlify-headers-parser | ^7.1.4
|
| proper-lockfile | ^4.1.2
|
⚠️ Peer Dependencies
This package defines 1 peer dependency.
| Peer | Version range |
|---|---|
| debug
| >=4.0.0
|
License
© 2022 - 2024 Giacomo Debidda // MIT License