我目前在我的Firebase项目中部署了两个云功能。一个是我的通用API('/ api'),它将在我的移动应用程序和Next.js应用程序之间共享。第二个('/ nextServer')是用于服务Next.js应用程序内容的函数:
我希望通用API在单独的环境中,以便我的移动和Web开发人员可以在其上进行协作。我想看看我设置的是最佳实践,还是只应直接从客户端查询'/ api'云函数,而不要通过Next.js提供的API
如果我要向客户提出请求:
const Home = () => {
const { data, error } = useSWR('/api/test', fetch)
console.log(data.toJson());
}
export default (req, res) => {
// Make call to firebase cloud function on the same server
res.statusCode = 200
res.json({ data: **data from cloud function** })
// Send the result back to the client
}
将调用从Next.js API路由到另一个云函数是否有意义,因为它们已经在同一服务器上了?我不想仅仅因为我通过提供的API重新路由而使查询变慢。