https://github.com/Smileupps/couchapp-chatty
Chatty is a couchapp linked to the Smileupps Chatty Tutorial, to learn building an instant-messaging web application, exclusively built on Javascript, HTML and CSS, using Apache CouchDB as all-in-one web app server, to deliver all presentation, business logic and data layers typical of a multi-tier architecture.
Chatty includes:
- a frontend for administration activities (user management / chat moderation)
- a frontend for regular users, intended for chatting: users only see their own conversations
- a secure server side API, stored as a Couchapp, implementing business rules and role based read/write ACLs
Chatty features:
- frontend access is restricted to authorized users only
- users have access to their own data only
- administration UI is restricted to administrators only
- frontend users are created by administrators, using the admin UI
- administrators can manage(insert/update/delete) all entities in the database (users, profiles, chat)
- a secure server side API implements custom business rules with user/role based ACLs for read, insert, update and delete operations
- updates to documents are automatically pushed in real-time to granted users, via long-polling
This app is part of Smileupps Ready to Run Examples. This means installation is as simple as:
- Installing Free Smileupps CouchDB Hosting from Smileupps App Store
- Checking your activation e-mail, which contains links to run it, access or edit its source code.
- Prerequisite: Apache CouchDB. You can download it from the CouchDB official homepage
-
If it's still in Admin Party, secure your CouchDB instance, by creating your own admin user. Click on Fix this in Futon's bottom-right corner
-
Download this couchapp to your local disk
-
Using your preferred Couchapp Deployment tool, upload your couchapp folder to your remote CouchDB instance, using chatty as database name.
-
Choose two domains to serve public UI and admin UI, such as chattypublic.yourdomain.com and chattyadmin.yourdomain.com
-
Adjust your DNS records, or /etc/hosts file, or C:\Windows\System32\drivers\etc\hosts file , to let these domains point directly to your CouchDB instance 127.0.0.1 chattypublic.yourdomain.com 127.0.0.1 chattyadmin.yourdomain.com
Use your CouchDB Hosting provider ip, if you are using an Hosted service
-
In your CouchDB configuration
-
in vhosts section create two new entries:
[vhosts] chattypublic.yourdomain.com = /chatty/_design/chatty/_rewrite/CONFIGSECRET/frontend/ chattyadmin.yourdomain.com = /chatty/_design/chatty/_rewrite/CONFIGSECRET/backend/
where CONFIGSECRET is the same as your couch_httpd_auth->secret CouchDB configuration value
- disable rewrites by setting httpd/secure_rewrites to false
-
-
Create a persistent replication document to continuously replicate users from chatty to _users
{ "source": "chatty", "target": "_users", "create_target": true, "continuous": true, "user_ctx": { "name": "admin", "roles": [ "_admin" ] }, "owner": "admin" }
-
Create chatty administration user:
curl -X PUT -k https://couchdb-root-url/chatty/_design/chatty/_rewrite/CONFIGSECRET/backend/user/org.couchdb.user:chatty -d "{\"name\":\"chatty\",\"password\":\"chatty\"}"
-
Secure it down all: prevent users from accessing futon or couchdb root directly, by using a proxy(e.g. haproxy) listening on ports 80 and 443, in front of couchdb. Proxy must be configured to forward to CouchDB port only requests with Host Header defined as chattypublic.yourdomain.com or chattyadmin.yourdomain.com domains. Requests without Host Header or with an incorrect value must be rejected by the proxy. In this way, allowed requests will then be handled exactly and only as defined in rewrites.json file defined within your design documents.