Utilities for working with the configuration files of various hosting providers.
npm install @jackdbd/hosting-utils
Note: this library was tested on Node.js >=18. It might work on other Node.js versions though.
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']
})
Read these resources to understand how to configure _headers
, serve.json
, vercel.json
.
vercel.json
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:*
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 |
© 2022 - 2024 Giacomo Debidda // MIT License