Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Couchapp Engine
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example/legacyapp add support of query parameters. Allows you to add value from one query
src
.gitignore initial release
LICENSE initial release
Makefile couchapp_legacy is now couchapp_ng .
NOTICE couchapp_legacy is now couchapp_ng .
README.rst
rebar
rebar.config couchapp_legacy is now couchapp_ng .
rebar.config.template

README.rst

About

couchapp_ng is a a new CouchApp engine for CouchDB.

Install

Make sure Couchdb is installed on folder above the couchapp_engine one. You can also change the path of couchdb installation by passing the path to **COUCHDB_SRC* environment variable..

$ make

(note during development you can use make dev command).

Add couch_ng_server server to couch configuration file local_dev.ini (or in production local.ini) and edit the following section:

[daemons]
couchapp_ng_routes={couchapp_ng_routes, start_link, []}

[httpd_design_handlers]
_app = {couchapp_ng_httpd, handle_app_req}

[couchapp_ng_handlers]
rewrite = {couchapp_ng_handlers, rewrite_handler}
proxy = {couchapp_ng_handlers, proxy_handler}

Start couchdb:

$ export $COUCHAPP_LEGACY=/path/to/couchapp_ng
$ ERL_FLAGS="-pa $COUCHAPP_LEGACY/ebin" ./utils/run

Now you can test the couchapp_ng rewriter. First install couchapp then go in the examples/legacyapp folder and do:

$ couchapp push testdb

This app for now allows you to test the rewriter. Rewrites rules are put in the routes property of your design documen:

[
    {
        "from": "^/blog/(?<post_no>\\w*)$",
        "to": "/_show/post/(?<post_no>)"
    },
    {
        "from": "^/about$",
        "to": "about.html",
        "type": "attachments"
    },
    {
        "from": "/page/:page",
        "to": "/_show/post/:page",
        "options": {
            "patterns": {
                "page": "\\w*"
            }
        }
    },
    {
        "from": "/(?<func>\\w*)-(?<name>\\w*)/(?<post_no>\\w*)$",
        "to": "/_(?<func>)/(?<name>)/(?<post_no>)"

    },
    {
        "from": "^/$",
        "to": "index.html"
    },
    {
        "from": "^/blah",
        "to": "index.html"
    },
    {
        "from": "^/index.html$"
    }
]

The couchapp_ng rewriter allows you to pass any regexp to your rule or use the reversed dispatching currently use in default CouchDB rewriter.

For example go on http://127.0.0.1:5984/testdb/_design/legacyapp/_app/ url. You will see the welcome page. This correspond to the rule:

{
    "from": "^/$",
    "to": "index.html"
}

You can also do such rule:

{
        "from": "^/blog/(?<post_no>\\w*)$",
        "to": "/_show/post/(?<post_no>)"
}

Go on http://127.0.0.1:5984/testdb/_design/legacyapp/_app/blog/test for example to see the result.

Or more complex rule:

{
"from": "/(?<func>\w*)-(?<name>\w*)/(?<post_no>\w*)$", "to": "/_(?<func>)/(?<name>)/(?<post_no>)"

}

Url http://127.0.0.1:5984/testdb/_design/legacyapp/_app/show-post/test

is rewritten to

http://127.0.0.1:5984/testdb/_design/legacyapp/_show/post/test

Reverse url dispatching is working too:

{
    "from": "/page/:page",
    "to": "/_show/post/:page",
    "options": {
        "patterns": {
            "page": "\\w*"
        }
    }
}

Url http://127.0.0.1:5984/testdb/_design/legacyapp/_app/page/test

is rewritten to

http://127.0.0.1:5984/testdb/_design/legacyapp/_app/_show/post/test

Note that you need to fix patterns here to have reverse dispatching working, which is a litte different from default couchapp engine.

More doc soon.

TODO:

  • Add Query paramenter in subtitutions variables
  • Replace shows/updates/lists by improved code.

Changelog:

version 0.01:

  • New Couchapp Rewriter
Something went wrong with that request. Please try again.