FT快递网络服务
创建 快递 要服务的中间软件 /__gtg, (中文(简体) ), /__health, (中文(简体) ), /__about,以及 /__error 结束点.
使用量
所需资源
运行快递网络服务需要 节点.js 20.x+ 和 (简体中文) 无。您可以安装 :
npm install @financial-times/express-web-service
你还需要使用 快递 4+. 快捷网络服务也支持 修复 稍作改动,见 实例 更多信息.
API 文档
熟悉情况 快递 在其余的API文件中假设。 您还需要使用以下模块:
const expressWebService = require("@financial-times/express-web-service")
expressWebService( [options] )
创建并返回一个服务 FT 网络服务端点的中间软件, 可用一个自定义 选项对象。 。 。 .
const app = express()
app.use(
expressWebService({
// options
})
)
// or mount on a sub-path
app.use(
"/example",
expressWebService({
// options
})
)
新增线路如下:
不错的去(/__gtg(中文(简体) )
向着 FT 状态良好,排放a 200 OK 如果申请被认为健康,则予以答复 503 Service Unavailable 如果它不应该。 目的是用来作出路线决定.
总是返回 200 OK 除下列情况外 goodToGoTest 选项.
健康检查(/__health(中文(简体) )
向着 FT 健康检查标准,返回JSON数据,总结应用程序目前的健康状况.
总是返回一个 [{ ok:true }] 健康检查反应(即有效的健康检查反应,单次检查),除非 healthCheck 选项.
关于( 关于)/__about(中文(简体) )
符合(在编写本报告时,草案) FT 关于终点标准,返回描述应用程序的JSON数据,并提供所有相关仪表板的链接和支持文件资源.
有关终点发布的信息来自 about 选项。 这个 _hostname 财务报告和审定财务报表 appVersion 字段将自动覆盖,如果在通过 about 选项.
错误( E)/__error(中文(简体) )
此端点只是丢出一个 JavaScript 错误, 而不尝试处理它 。 这对于测试您的应用程序处理 prod 中的运行时间错误的方式很有用, 既包括报告错误( 例如记录或聚合工具), 也包括向终端用户提交适当的 UI .
选项
现有备选方案如下:
manifestPath: (可选) 应用程序路径package.json文档。 这将用来填充appVersion财务报告和审定财务报表dateDeployed属性/__about如果未明确指明,则结束点about: (可选) 含有标准运行本属性的对象,定义如下: ft 关于终点标准,或者一个解决包含这些属性的对象的保证goodToGoTest: (可选) 用于表示服务状态的功能,该功能应返回一个解决了的许诺true以显示积极的状态false以表示对去状态的负面效果healthCheck: (可选) 用于生成结构化健康检查信息的函数,该函数应返回用一系列健康检查对象解决的许诺routes: (可选)要安装的路由数组. 可能值为health, (中文(简体) ),gtg, (中文(简体) ),about财务报告和审定财务报表error默认为["health", "gtg", "about"]
实例
基本实例:
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逻辑和健康检查逻辑示例 :
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()
}
]);
});
}
}));
使用实例 修复 而非快报 :
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中件:
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),也可以接受解决对象的许诺。 这使得您能够同步生成您的信息 :
app.use(
expressWebService({
about: {
name: "My App",
},
})
)
// or
app.use(
expressWebService({
about: new Promise((resolve, reject) => {
// do something async
resolve(retrievedAboutInfo)
}),
})
)
捐款
这个模块有一套完整的单元测试,通过ESLint验证. 您可以在打开拉出请求前使用下列命令来检查您的代码 .
make verify # verify JavaScript code with ESLint
make test # run the unit tests and check coverage
联系人
如果您对本单元有任何问题或评论,或需要帮助使用,请 提出问题访问 #origami - 支持 或电子邮件 折纸支持。 。 。 .
许可证
本软件由金融时报根据以下规定出版: 麻省理工学院许可证。 。 。 .