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

时间:2014-10-03 14:22:24

标签: couchdb

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

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

这是否可以使用show function return对象,或者是CouchDB内部以外的HTTP返回码禁止?

1 个答案:

答案 0 :(得分:3)

不确定。只需使用正确的HTTP重定向状态代码指定code attribute

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