From 9a17934c9349fac6ba88d57dc1fd0c222425004a Mon Sep 17 00:00:00 2001 From: Aurelien Benel Date: Sun, 17 May 2015 17:59:18 +0200 Subject: [PATCH] REFACTORING: Register as a new user (closes #28). The static pages and rewriting to CouchDB `_users` database are no more served by a CouchDB app but by AAAforREST itself. Additional settings and installing are no more required. A virtual server (`auth.*`) is always on for this. --- README.md | 5 ----- app/proxy.js | 11 ++++++++++- conf/config.sample.js | 5 +++++ db/_id | 1 - db/couchapp.json | 3 --- db/rewrites.json | 7 ------- package.json | 2 ++ {db/_attachments => public}/jquery.js | 0 {db/_attachments => public}/register.css | 0 {db/_attachments => public}/register.html | 0 {db/_attachments => public}/register.js | 0 11 files changed, 17 insertions(+), 17 deletions(-) delete mode 100644 db/_id delete mode 100644 db/couchapp.json delete mode 100644 db/rewrites.json rename {db/_attachments => public}/jquery.js (100%) rename {db/_attachments => public}/register.css (100%) rename {db/_attachments => public}/register.html (100%) rename {db/_attachments => public}/register.js (100%) diff --git a/README.md b/README.md index 821e9c6..df9ddab 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,3 @@ Installation procedure * The service can be stopped with: sudo forever stop app/proxy.js - -* The (optional) Web interface can be installed in CouchDB with: - - curl -X PUT -d '"false"' localhost:5984/_config/httpd/secure_rewrites - couchapp push --browse db http://localhost:5984/aaaforrest diff --git a/app/proxy.js b/app/proxy.js index ad51818..9efba58 100644 --- a/app/proxy.js +++ b/app/proxy.js @@ -1,4 +1,6 @@ -var app = require('express')(); +var express = require('express'); +var vhost = require('vhost'); +var proxy = require('express-http-proxy'); var http = require('http'); var url = require('url'); var async = require('async'); @@ -232,6 +234,13 @@ function parseHttpCredentials(context) { } } +var userApp = express.Router(); +userApp.use(express.static('public')); +userApp.route('/_users/*').all(proxy(configuration.users || 'localhost:5984')); + +var app = express(); +app.use(vhost('auth.*', userApp)); + app.use(function(requestIn, responseOut, next) { var context = { requestIn: requestIn, diff --git a/conf/config.sample.js b/conf/config.sample.js index 110ea02..c12d9fe 100644 --- a/conf/config.sample.js +++ b/conf/config.sample.js @@ -10,6 +10,11 @@ module.exports = { */ //port: 80, + /** + * CouchDB service hosting _users database. + */ + //users: 'localhost:5984', + sites: [{ /** diff --git a/db/_id b/db/_id deleted file mode 100644 index 204ddb9..0000000 --- a/db/_id +++ /dev/null @@ -1 +0,0 @@ -_design/aaaforrest \ No newline at end of file diff --git a/db/couchapp.json b/db/couchapp.json deleted file mode 100644 index 40fe69b..0000000 --- a/db/couchapp.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "index" : "_rewrite/register.html" -} diff --git a/db/rewrites.json b/db/rewrites.json deleted file mode 100644 index 2911a43..0000000 --- a/db/rewrites.json +++ /dev/null @@ -1,7 +0,0 @@ -[{ - "from": "_users/:user", - "to": "../../../_users/:user" -},{ - "from": "*", - "to": "*" -}] diff --git a/package.json b/package.json index 48fddff..82cd46e 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "version": "1.2015.0430", "dependencies": { "express": ">=4.9", + "vhost": ">=2.0", + "express-http-proxy": ">=0.6", "ldapjs": ">=0.7.x", "winston": ">=0.8.x", "async": ">=0.9.x", diff --git a/db/_attachments/jquery.js b/public/jquery.js similarity index 100% rename from db/_attachments/jquery.js rename to public/jquery.js diff --git a/db/_attachments/register.css b/public/register.css similarity index 100% rename from db/_attachments/register.css rename to public/register.css diff --git a/db/_attachments/register.html b/public/register.html similarity index 100% rename from db/_attachments/register.html rename to public/register.html diff --git a/db/_attachments/register.js b/public/register.js similarity index 100% rename from db/_attachments/register.js rename to public/register.js