需要用 google 助手添加中间件

Need to add Middleware with google assistant

我正在设置一个 sessionToken,为此我需要在 google 助手中添加一个中间件。虽然同样可以使用 express 轻松完成,但我不确定如何通过 google 辅助网络服务来实现。

从根本上说,函数是一个隐藏在幕后的 Express.js 服务器,但不会向您展示 Express 的所有配置选项。你有几个选择。

最简单的方法是在您的函数中显式调用中间件本身。来自 Google's documentation:

If you need to inject middleware dependencies for things like cookie support or CORS, call these within the function. For example, to enable CORS support, add the following block:

// Enable CORS using the `cors` express middleware.
cors(req, res, () => {
  // ...
});

还有更精细的方法可以挂接到底层 Express 框架。详情请参阅 and this followup blog post