返回CouchDB show函数中的重定向HTTP状态代码



我的CouchDB中有一个非常标准的show函数,但对于某些路径,我想通过303重定向到另一个页面。请参阅其他。

function(doc, req) {
  return {
    body : '<h1>' + doc.title + '</h1>',
    headers : {
      "Content-Type" : "text/html",
      "¿¿¿Response-Code???": 303
    }
  }
}

使用show函数返回对象,或者HTTP返回代码在CouchDB内部之外是禁止的吗?

当然。只需使用正确的HTTP重定向状态代码指定代码属性:

function(doc, req) {
  return {
    code : 302,
    body : '<h1>' + doc.title + '</h1>',
    headers : {
      "Content-Type" : "text/html",
      "Location": "http://example.com"
    }
  }
}

最新更新