Pergunta

I have couchapp that is working fine.

This works: http://domain.com/file.html
This does not: http://domain.com/file

I want it to understand that if there is no extension, it should try the .html extension.

I'm not sure if this is a _rewrite rule (which I am using to prettify my URLs) or something else.

Foi útil?

Solução

AFAIK rewrites cannot currently be used to add a suffix to a matched variable in a URL path.

An alternative approach you could use is to put the content of file.html into a document with id "file" under a given key (named "content" or similar), create a show function [1] (calling it something like "render") that outputs the value of that key with content type "text/html" and then create a rewriter such as:

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

The complete design doc would look like this:

{
  "_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"
    }
  ]
}

And the corresponding doc:

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

I've shared an example which follows the above pattern [2].

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

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top