0

私は正常に動作しているcouchappを持っています。

これは機能します: http://domain.com/file.html
これは機能しません: http://domain.com/file

拡張子がない場合は、.html 拡張子を試す必要があることを理解してもらいたい。

これが _rewrite ルール (URL をきれいにするために使用している) なのか、それとも何か他のものなのかはわかりません。

4

1 に答える 1

3

現在のところ、書き換えを使用して、URL パス内の一致する変数にサフィックスを追加することはできません。

使用できる代替アプローチは、file.html のコンテンツを特定のキー (「content」などの名前) の下の ID「file」を持つドキュメントに配置し、show 関数 [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

于 2013-05-21T13:15:52.723 に答える