【问题标题】:How to get a couchapp to serve a file with no extension (implied .html)如何让 couchapp 提供没有扩展名的文件(隐含 .html)
【发布时间】:2013-05-21 04:28:11
【问题描述】:

我的 couchapp 运行良好。

这有效:http://domain.com/file.html
这不是:http://domain.com/file

我想让它明白,如果没有扩展名,它应该尝试 .html 扩展名。

我不确定这是 _rewrite 规则(我用来美化我的 URL)还是其他什么。

【问题讨论】:

    标签: couchdb couchbase couchapp


    【解决方案1】:

    AFAIK 重写目前不能用于向 URL 路径中的匹配变量添加后缀。

    您可以使用的另一种方法是将 file.html 的内容放入一个给定键(名为“content”或类似名称)下的 id 为“file”的文档中,创建一个显示函数 [1](将其命名为像“render”)输出内容类型为“text/html”的键的值,然后创建一个重写器,例如:

    {
        "from": "/:doc",
        "to": "/_show/render/:doc",
        "method": "GET",
        "query": {
        }
    }
    

    完整的设计文档如下所示:

    {
      "_id": "_design/rewrite",
      "shows": {
        "render": "function(doc) { return { headers: { \"Content-Type\": \"text/html\"}, body: doc.content } }"
      },
      "rewrites": [
        {
          "query": {},
          "method": "GET",
          "to": "/_show/render/:doc",
          "from": "/:doc"
        }
      ]
    }
    

    以及对应的文档:

    {
      "_id": "file",
      "content": "<html>html content of doc goes here</html>"
    }
    

    我分享了一个遵循上述模式 [2] 的示例。

    [1]http://wiki.apache.org/couchdb/Formatting_with_Show_and_List

    [2]https://mikewallace.cloudant.com/rewriter/_design/rewrite/_rewrite/file

    【讨论】:

      最近更新 更多