@defra/hapi-secure-context

中文文档
0.4.2发布于 2026/11/04OGL-UK-3.0ES Module零依赖构建来源已验证近 30 天下载 4.8万

A hapi plugin loading extra CA certs

原始使用文档
文档目录5 节
  1. Installing
  2. Usage
  3. Register the plugin
  4. Options
  5. Usage

Hapi SecureContext

A plugin to load custom CA certs into node's tls.secureContext.

Installing

npm install @defra/hapi-secure-context

Usage

The plugin will load custom certificates from environment variable. This is controlled via the plugin's options during registration.

Register the plugin

This should be done when creating the server.

import { secureContext } from '@defra/hapi-secure-context'

await server.register({
  plugin: secureContext.plugin,
  options: {}
})

By default, the plugin will attempt to load certificates from any environment variable starting with TRUSTSTORE_.

Options

The plugin suports the following options:

  • keys
  • prefix

Keys

Setting keys restricts the plugin to only load certificates from environment variables in the list. The environment variables must contain a base64 encoded certificate.

await server.register({
  plugin: secureContext.plugin,
  options: { keys: ['CERT_1', 'CERT_2'] }
})

Prefix

Setting prefix overrides the default prefix.

await server.register({
  plugin: secureContext.plugin,
  options: { prefix: 'MY_CUSTOM_PREFIX_' }
})

In the above example it will attempt to load any environment variable that begins with MY_CUSTOM_PREFIX_.

Usage

After registering, any certificate will be added to the default secureContext. Libraries that use the default node tls.secureContext will pick up these certs automatically.

The plugin will decorate the server object with an instance of secureContext, e.g. server.secureContext.

If you want to load the custom certificates manually, the plugin also decorates the server object with a customCACerts field. This contains an

版本与发布记录

@defra/hapi-secure-context 共发布 10 个版本,首次发布于 2025/07/24;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.2latest2026/11/048 天前
0.4.12026/10/051 个月前
0.4.02025/11/071 年前
0.3.02025/09/021.2 年前
0.2.02025/08/261.2 年前
0.1.42025/07/251.3 年前

关于 @defra/hapi-secure-context 的常见问题

@defra/hapi-secure-context 是什么?

A hapi plugin loading extra CA certs

如何安装 @defra/hapi-secure-context?

在项目目录运行 npm install @defra/hapi-secure-context,或使用 pnpm add / yarn add / bun add。

@defra/hapi-secure-context 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/defra__hapi-secure-context 是否存在。

@defra/hapi-secure-context 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@defra/hapi-secure-context 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@defra/hapi-secure-context 可以商用吗?

@defra/hapi-secure-context 使用 OGL-UK-3.0 许可。声明的许可为 OGL-UK-3.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@defra/hapi-secure-context 的下载量有多少?

根据 npm 官方下载统计,@defra/hapi-secure-context 在 2026/10/12 – 2026/11/10 这 30 天内被下载 48,167 次,日均约 1,606 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@defra/hapi-secure-context 还在维护吗?

最新版本 0.4.2 发布于 2026/11/04(8 天前);至今共发布 10 个版本,其中过去 12 个月发布了 2 个;首次发布于 2025/07/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。