iriscouch / follow

Very stable, very reliable, NodeJS CouchDB _changes follower
Apache License 2.0
393 stars 82 forks source link

Changes and rewites #20

Open abarysiuk opened 12 years ago

abarysiuk commented 12 years ago

I found that feed.db = 'http://myvhost.com/alias_db' won't work, where: myvhost.com = real_host/real_db/_design/app/_rewrite/

rewrite { "from": "/alias_db/", "to": "../../*" }

It simply hangs and print nothing. I'm able to get result via feed.db = real_host/real_db. Also i'm able to get changes set via 'curl http://myvhost.com/alias_db/_changes'.

jhs commented 11 years ago

Very interesting. I think Follow will try to confirm the database first, so perhaps it is failing there. Do you have any 4xx or 5xx messages in your server log?

abarysiuk commented 11 years ago

Good point about the logs! I think i found the problem. So rewrite

{
    "from": "/alias_db/",
    "to": "../../*"
}

cause 'curl http://myvhost.com/alias_db' return information about real db, like:

{"db_name":"real_db"  ...

But 'curl http://myvhost.com/alias_db/_changes' doesn't work - rewire is translated into /real_db/_design/app/alias_db/_changes = 404

Changing rewrite to:

{
    "from": "/alias_db/*",  <- * symbol at the end
    "to": "../../*"
}

cause 'curl http://myvhost.com/alias_db' return:

{"error":"not_found","reason":"Document is missing attachment"}

and Follow throws error:

[Error: Bad DB response: {"error":"not_found","reason":"Document is missing attachment"}]

I don't know yet how to write such rewrite that will handle both cases well /