An open API service indexing awesome lists of open source software.

https://github.com/benoitc/couchapp-ng

Couchapp Engine
https://github.com/benoitc/couchapp-ng

Last synced: 11 months ago
JSON representation

Couchapp Engine

Awesome Lists containing this project

README

          

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/(?\\w*)$",
"to": "/_show/post/(?)"
},
{
"from": "^/about$",
"to": "about.html",
"type": "attachments"
},
{
"from": "/page/:page",
"to": "/_show/post/:page",
"options": {
"patterns": {
"page": "\\w*"
}
}
},
{
"from": "/(?\\w*)-(?\\w*)/(?\\w*)$",
"to": "/_(?)/(?)/(?)"

},
{
"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/(?\\w*)$",
"to": "/_show/post/(?)"
}

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": "/(?\\w*)-(?\\w*)/(?\\w*)$",
"to": "/_(?)/(?)/(?)"
}

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