提问者:小点点

在云功能中做“重定向”后的事情?


我想在重定向用户后写入DB:

 exports.contentServer = functions.https.onRequest((request, response) => {
...
...
    return response.redirect(finalUrl + "front?action=" + action ) 
 
     .then(function(){   //  **** error : .then of undefined
        ....

我得到了一个错误的承诺。

Cannot read property 'then' of undefined
    at exports.contentServer.functions.https.onRequest
           

共1个答案

匿名用户

据我所知,redirection不返回promise。 实际上,从错误消息中的undefined来看,它似乎根本没有返回任何内容。 文档也没有显示任何返回值:https://expressjs.com/en/api.html#res.redirect

如果它要返回一些东西,您可以捕获该值并在以后返回它:

const result = response.redirect(finalUrl + "front?action=" + action ) 

....

return result;