# @financial-times/express-web-service 中文文档

规范地址：https://npmcn.com/package/%40financial-times/express-web-service/

版本：5\.0\.0
npm 元数据更新时间：2026-10-06T13:38:25.959Z
中文译文更新时间：2026-11-14T18:17:44.230Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40financial-times/express-web-service
原文对照：https://npmcn.com/package/%40financial-times/express-web-service/?lang=original
项目主页：https://github.com/Financial-Times/express-web-service
源码仓库：https://github.com/Financial-Times/express-web-service

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：47.5 kB，26 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=20
- 运行依赖：2 个
- 首次发布：2017-01-11T15:19:27.570Z
- 最新版本发布：2025-02-27T15:41:11.517Z
- 近 30 天下载量：2831（2026-10-15 至 2026-11-13，npm 官方下载统计）
- 已发布版本数：8（近 12 个月 0 个）

## 中文简介

创建Express 中间软件以服务于 / gtg,/ 健康,/ 左右,和/ ERror端点.

## 安装

```sh
npm install @financial-times/express-web-service
```

也可以使用：`pnpm add @financial-times/express-web-service`、`yarn add @financial-times/express-web-service`、`bun add @financial-times/express-web-service`

## README

# FT快递网络服务

创建 [快递](http://expressjs.com/) 要服务的中间软件 `/__gtg`, (中文(简体) ), `/__health`, (中文(简体) ), `/__about`,以及 `/__error` 结束点.

-   [使用量](https://npmcn.com/package/%40financial-times/express-web-service/#readme-usage)
    -   [所需资源](https://npmcn.com/package/%40financial-times/express-web-service/#readme-requirements)
    -   [API 文档](https://npmcn.com/package/%40financial-times/express-web-service/#readme-api-documentation)
    -   [选项](https://npmcn.com/package/%40financial-times/express-web-service/#readme-options)
    -   [实例](https://npmcn.com/package/%40financial-times/express-web-service/#readme-examples)
-   [移徙](https://npmcn.com/package/%40financial-times/express-web-service/#readme-migration)
-   [捐款](https://npmcn.com/package/%40financial-times/express-web-service/#readme-contributing)
-   [联系人](https://npmcn.com/package/%40financial-times/express-web-service/#readme-contact)
-   [许可证](https://npmcn.com/package/%40financial-times/express-web-service/#readme-licence)

## 使用量

### 所需资源

运行快递网络服务需要 [节点.js](https://nodejs.org/) 20.x+ 和 (简体中文) [无](https://www.npmjs.com/)。您可以安装 :

```sh
npm install @financial-times/express-web-service
```

你还需要使用 [快递](http://expressjs.com/) 4+. 快捷网络服务也支持 [修复](http://restify.com/) 稍作改动,见 [实例](https://npmcn.com/package/%40financial-times/express-web-service/#readme-examples) 更多信息.

### API 文档

熟悉情况 [快递](http://expressjs.com/) 在其余的API文件中假设。 您还需要使用以下模块:

```js
const expressWebService = require("@financial-times/express-web-service")
```

### `expressWebService( [options] )`

创建并返回一个服务 FT 网络服务端点的中间软件, 可用一个自定义 [选项对象](https://npmcn.com/package/%40financial-times/express-web-service/#readme-options)。 。 。 .

```js
const app = express()

app.use(
    expressWebService({
        // options
    })
)

// or mount on a sub-path
app.use(
    "/example",
    expressWebService({
        // options
    })
)
```

新增线路如下:

#### 不错的去(`/__gtg`(中文(简体) )

向着 [FT 状态良好](https://docs.google.com/document/d/11paOrAIl9eIOqUEERc9XMaaL3zouJDdkmb-gExYFnw0/edit),排放a `200 OK` 如果申请被认为健康,则予以答复 `503 Service Unavailable` 如果它不应该。 目的是用来作出路线决定.

总是返回 `200 OK` 除下列情况外 `goodToGoTest` 选项.

#### 健康检查(`/__health`(中文(简体) )

向着 [FT 健康检查标准](https://docs.google.com/document/d/18hefJjImF5IFp9WvPAm9Iq5_GmWzI9ahlKSzShpQl1s/edit),返回JSON数据,总结应用程序目前的健康状况.

总是返回一个 `[{ ok:true }]` 健康检查反应(即有效的健康检查反应,单次检查),除非 `healthCheck` 选项.

#### 关于( 关于)`/__about`(中文(简体) )

符合(在编写本报告时,草案) [FT 关于终点标准](https://docs.google.com/document/d/1B80a0nAI8L1cuIlSEai4Zuztq7Lef0ytxJYNFCjG7Ko/edit),返回描述应用程序的JSON数据,并提供所有相关仪表板的链接和支持文件资源.

有关终点发布的信息来自 `about` 选项。 这个 `_hostname` 财务报告和审定财务报表 `appVersion` 字段将自动覆盖,如果在通过 `about` 选项.

#### 错误( E)`/__error`(中文(简体) )

此端点只是丢出一个 JavaScript 错误, 而不尝试处理它 。 这对于测试您的应用程序处理 prod 中的运行时间错误的方式很有用, 既包括报告错误( 例如记录或聚合工具), 也包括向终端用户提交适当的 UI .

### 选项

现有备选方案如下:

-   `manifestPath`: (可选) 应用程序路径 `package.json` 文档。 这将用来填充 `appVersion` 财务报告和审定财务报表 `dateDeployed` 属性 `/__about` 如果未明确指明,则结束点
-   `about`: (可选) 含有标准运行本属性的对象,定义如下: [ft 关于终点标准](https://docs.google.com/document/d/1B80a0nAI8L1cuIlSEai4Zuztq7Lef0ytxJYNFCjG7Ko/edit),或者一个解决包含这些属性的对象的保证
-   `goodToGoTest`: (可选) 用于表示服务状态的功能,该功能应返回一个解决了的许诺 `true` 以显示积极的状态 `false` 以表示对去状态的负面效果
-   `healthCheck`: (可选) 用于生成结构化健康检查信息的函数,该函数应返回用一系列健康检查对象解决的许诺
-   `routes`: (可选)要安装的路由数组. 可能值为 `health`, (中文(简体) ), `gtg`, (中文(简体) ), `about` 财务报告和审定财务报表 `error`默认为 `["health", "gtg", "about"]`

### 实例

基本实例:

```JS
const express = require('express');
const expressWebService = require('@financial-times/express-web-service');

const app = express();

app.use(expressWebService({
    manifestPath: `${__dirname}/package.json`,
    about: {
        "schemaVersion": 1,
        "name": "build-service",
        "purpose": "Front end build process as a service.  Fetches specified Origami components from git, runs Origami build process, and returns the resulting CSS or JS bundle over HTTP.",
        "audience": "public",
        "primaryUrl": "https://origami-build.ft.com",
        "serviceTier": "gold"
    }
}));
```

GoodTo Go逻辑和健康检查逻辑示例 :

```JS
app.use(expressWebService({
    manifestPath: `${__dirname}/package.json`,
    about: {
        "schemaVersion": 1,
        "name": "build-service",
        "purpose": "Front end build process as a service.  Fetches specified Origami components from git, runs Origami build process, and returns the resulting CSS or JS bundle over HTTP.",
        "audience": "public",
        "primaryUrl": "https://origami-build.ft.com",
        "serviceTier": "gold"
    },
    goodToGoTest: function() {
        return new Promise(function(resolve, reject) {
            resolve(isApplicationHappy());
        });
    },
    healthCheck: function() {
        // You might have several async checks that you need to perform or
        // collect the results from, this is a really simplistic example
        return new Promise(function(resolve, reject) {
            resolve([
                {
                    name: "Database TCP connectivity",
                    ok: false,
                    severity: 2,
                    businessImpact: "Article pages will not be available",
                    technicalSummary: "The database is dead",
                    panicGuide: "Check the health status of the database at host <database host>",
                    checkOutput: "tcp connect failed after 10 seconds on destination port 3306 - destination unreachable",
                    lastUpdated: new Date().toISOString()
                }
            ]);
        });
    }
}));
```

使用实例 [修复](http://restify.com/) 而非快报 :

```js
const expressWebService = require("@financial-times/express-web-service")
const restify = require("restify")

const server = restify.createServer()

// Because Restify doesn't mount middleware for routes that don't exist,
// we have to explicitly define the required routes
server.get(
    /^\/__(about|gtg|health)$/,
    expressWebService({
        // config
    })
)
```

## 移徙

此迁移指南旨在帮助您在Express Web Service的主要版本之间迁移.

### 从v2.x.x迁移到v3.x.x.x

这个库2和3版本之间有一些大的变化. 首先,该单元已经从 `express-ftwebservice` 改为 `@financial-times/express-web-service`。 。 。 .

整个API被更新为使用Express中件:

```js
const express = require("express")
const expressWebService = require("@financial-times/express-web-service")
const app = express()
const options = {}

// Old
expressWebService(app, options)

// New
app.use(expressWebService(options))
```

同时 `about` 选项现在可以接受对象(匹配版本2),也可以接受解决对象的许诺。 这使得您能够同步生成您的信息 :

```js
app.use(
    expressWebService({
        about: {
            name: "My App",
        },
    })
)
// or
app.use(
    expressWebService({
        about: new Promise((resolve, reject) => {
            // do something async
            resolve(retrievedAboutInfo)
        }),
    })
)
```

## 捐款

这个模块有一套完整的单元测试,通过ESLint验证. 您可以在打开拉出请求前使用下列命令来检查您的代码 .

```sh
make verify  # verify JavaScript code with ESLint
make test    # run the unit tests and check coverage
```

## 联系人

如果您对本单元有任何问题或评论,或需要帮助使用,请 [提出问题](https://github.com/Financial-Times/express-web-service/issues)访问 [#origami - 支持](https://financialtimes.slack.com/messages/origami-support/) 或电子邮件 [折纸支持](mailto:origami-support@ft.com)。 。 。 .

## 许可证

本软件由金融时报根据以下规定出版: [麻省理工学院许可证](http://opensource.org/licenses/MIT)。 。 。 .

## 常见问题

### @financial-times/express-web-service 是什么？

创建Express 中间软件以服务于 / gtg,/ 健康,/ 左右,和/ ERror端点\.

### 如何安装 @financial-times/express-web-service？

在项目目录运行 npm install @financial-times/express-web-service，或使用 pnpm add / yarn add / bun add。

### @financial-times/express-web-service 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/financial-times\_\_express-web-service 是否存在。

### @financial-times/express-web-service 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @financial-times/express-web-service 需要什么版本的 Node\.js？

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

### @financial-times/express-web-service 可以商用吗？

@financial-times/express-web-service 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @financial-times/express-web-service 的下载量有多少？

根据 npm 官方下载统计，@financial-times/express-web-service 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,831 次，日均约 94 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @financial-times/express-web-service 还在维护吗？

最新版本 5\.0\.0 发布于 2025/02/27（1\.7 年前）；至今共发布 8 个版本，其中过去 12 个月发布了 0 个；首次发布于 2017/01/11。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

