同步的 HTTP 微服务
微-同步HTTP微服务
□ 特性
同步 ' 和等待'** 免责声明:** 微型是用于容器内部的,并非用于无服务器环境。 对于使用Vercel的人来说,这意味着不需要在您的项目中使用Micro,因为Micro提供的惠益不适用于平台. 微公司提供的“json”等功能特性以[Serverless 函数助手(https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-request-and-response-objects)的形式随时提供。
□ 安装
** 重要性:** 微分只用于生产. 在开发中,您应当使用micro-dev,它为您提供了一个专门为了开发微服务而定制的工具带.
为了准备在生产环境中运行的微服务,首先安装 " 微 " :
(原始内容存档于2019-09-29) (英语). ```bash npm install --save micro
□ 使用量
创建 “ index.js” 文件并导出一个接受标准 [http.incomingMessage] (https://nodejs.org/api/http.html#http_class_http_incomingmessage) 和 [http.ServerResponse] (https://nodejs.org/api/http.html#http_class_http_serverresponse) 对象的函数:
ZZ1ZZ
micro提供[有用的帮助 (https://github.com/vercel/micro#body-parsing) , 但也处理返回值 – 这样您可以写得更短!
(原始内容存档于2019-09-29). ```js
module.exports = () => 'Welcome to Micro';其次,确保package.json'内的主要'财产指向你的微服务(本例中的index.js'),并增加开始'脚本:
贾森 { "主":"index.js","index". "文稿"曰: