Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3616F1864F for ; Tue, 26 May 2015 11:10:52 +0000 (UTC) Received: (qmail 63288 invoked by uid 500); 26 May 2015 11:10:52 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 63239 invoked by uid 500); 26 May 2015 11:10:51 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 63229 invoked by uid 99); 26 May 2015 11:10:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 May 2015 11:10:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B8FFEDFCF1; Tue, 26 May 2015 11:10:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: garren@apache.org To: commits@couchdb.apache.org Message-Id: <66534f723201461e99dcfb9c7fdd0883@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: fauxton commit: updated refs/heads/master to f933723 Date: Tue, 26 May 2015 11:10:51 +0000 (UTC) Repository: couchdb-fauxton Updated Branches: refs/heads/master 455f0a53b -> f93372389 Fauxton Server for use with NPM This allows Fauxton to be installed via npm so that we can release newer versions of Fauxton for users to try out. $ npm install fauxton -g $ fauxton or see `fauxton --help` for options Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/f9337238 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/f9337238 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/f9337238 Branch: refs/heads/master Commit: f93372389e1780cd8d9e9baf00cab86783673cb8 Parents: 455f0a5 Author: Garren Smith Authored: Mon Apr 27 13:29:54 2015 +0100 Committer: Garren Smith Committed: Tue May 26 13:10:17 2015 +0200 ---------------------------------------------------------------------- Gruntfile.js | 10 +-- app/addons/documents/shared-views.js | 3 +- bin/fauxton | 31 +++++++++ bin/grunt | 18 ------ favicon.ico | Bin 1150 -> 9326 bytes index.js | 102 ++++++++++++++++++++++++++++++ package.json | 21 ++++-- readme.md | 31 +++++---- 8 files changed, 174 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f9337238/Gruntfile.js ---------------------------------------------------------------------- diff --git a/Gruntfile.js b/Gruntfile.js index bd6b9d7..ef035aa 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -332,15 +332,17 @@ module.exports = function (grunt) { dist:{ files:[ - {src: "dist/debug/index.html", dest: "dist/release/index.html"}, - {src: assets.img, dest: "dist/release/img/", flatten: true, expand: true}, - {src: assets.fonts, dest: "dist/release/fonts/", flatten: true, expand: true} + {src: 'dist/debug/index.html', dest: 'dist/release/index.html'}, + {src: assets.img, dest: 'dist/release/img/', flatten: true, expand: true}, + {src: assets.fonts, dest: 'dist/release/fonts/', flatten: true, expand: true}, + {src: './favicon.ico', dest: "dist/release/favicon.ico"} ] }, debug:{ files:[ {src: assets.fonts, dest: "dist/debug/fonts/", flatten: true, expand: true}, - {src: assets.img, dest: "dist/debug/img/", flatten: true, expand: true} + {src: assets.img, dest: "dist/debug/img/", flatten: true, expand: true}, + {src: './favicon.ico', dest: "dist/debug/favicon.ico"} ] } }, http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f9337238/app/addons/documents/shared-views.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/shared-views.js b/app/addons/documents/shared-views.js index e5b5f17..fa14731 100644 --- a/app/addons/documents/shared-views.js +++ b/app/addons/documents/shared-views.js @@ -48,7 +48,7 @@ function (app, FauxtonAPI, Components, Documents, Databases) { permissionsLink = '#' + FauxtonAPI.urls('permissions', 'app', safeDatabaseName), databaseUrl = FauxtonAPI.urls('allDocs', 'app', safeDatabaseName, ''), db_url = FauxtonAPI.urls('allDocs', 'server', safeDatabaseName, ''), - base = FauxtonAPI.urls('base', 'app', safeDatabaseName); + base = '#' + FauxtonAPI.urls('base', 'app', safeDatabaseName); return { changesUrl: changesLink, @@ -318,4 +318,3 @@ function (app, FauxtonAPI, Components, Documents, Databases) { return Views; }); - http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f9337238/bin/fauxton ---------------------------------------------------------------------- diff --git a/bin/fauxton b/bin/fauxton new file mode 100755 index 0000000..0d6e1f0 --- /dev/null +++ b/bin/fauxton @@ -0,0 +1,31 @@ +#!/usr/bin/env node + +var optimist = require('optimist') + .usage('Fauxton server \nUsage: $0') + .options('couchdb', { + alias : 'c', + default : 'http://localhost:5984', + describe: 'Url to your CouchDB instance' + }) + .options('port', { + alias : 'p', + default : 8000, + describe: 'Local port that Fauxton will run on' + }) + .options('help', { + alias : 'h', + describe: 'Show this message' + }) + .options('contentSecurityPolicy', { + alias : 'csp', + default : true, + describe: 'Configure the content security policy' + }); + +var argv = optimist.argv; + +if (argv.help || argv.h) { + return optimist.showHelp(console.log); +} + +var server = require('..')(argv); http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f9337238/bin/grunt ---------------------------------------------------------------------- diff --git a/bin/grunt b/bin/grunt deleted file mode 100755 index 2c52393..0000000 --- a/bin/grunt +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -REL_PATH="`dirname \"$0\"`" -GRUNT_PATH="$REL_PATH/../node_modules/.bin/grunt" - -$GRUNT_PATH $* http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f9337238/favicon.ico ---------------------------------------------------------------------- diff --git a/favicon.ico b/favicon.ico index 0baa6f3..34bfaa8 100644 Binary files a/favicon.ico and b/favicon.ico differ http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f9337238/index.js ---------------------------------------------------------------------- diff --git a/index.js b/index.js new file mode 100644 index 0000000..b6aec17 --- /dev/null +++ b/index.js @@ -0,0 +1,102 @@ +var path = require("path"); +var http = require("http"); +var httpProxy = require('http-proxy'); +var send = require('send'); +var urlLib = require('url'); +var _ = require('lodash'); +var dist_dir = __dirname + '/dist/release/'; + +module.exports = function (options) { + // Options + var setContentSecurityPolicy = options.contentSecurityPolicy; + var port = options.port; + var proxyUrl = options.couchdb; + + function sendFile (req, res, filePath) { + return send(req, filePath) + .on('error', function (err) { + if (err.status === 404) { + console.log('Could not locate', filePath); + } else { + console.log('ERROR', filePath, err); + } + + res.setHeader("Content-Type", "text/javascript"); + res.statusCode = 404; + res.end(JSON.stringify({error: err.message})); + }) + .pipe(res); + } + + var fileTypes = ['js', 'css','png', 'swf', 'eot', 'woff', 'svg', 'ttf', 'swf']; + + function isFile (url) { + var arr = url.split('.'); + + if (arr.length < 2) { + return false; + } + + return _.contains(fileTypes, arr[1]); + } + + // create proxy to couch for all couch requests + var proxy = httpProxy.createServer({ + target: proxyUrl + }); + + http.createServer(function (req, res) { + var isDocLink = /_utils\/docs/.test(req.url) ? true : false; + var url = req.url.split(/\?v=|\?noCache/)[0].replace('_utils', ''); + var accept = req.headers.accept.split(','); + + if (setContentSecurityPolicy) { + var headerValue = "default-src 'self'; img-src 'self' data:; font-src 'self'; " + + "script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline';"; + res.setHeader('Content-Security-Policy', headerValue); + } + + if (url === '/' && accept[0] !== 'application/json') { + // serve main index file from here + return sendFile(req, res, path.join(dist_dir, 'index.html')); + } else if (isFile(url) && !isDocLink ) { + return sendFile(req, res, path.join(dist_dir, url)); + } + + // This sets the Host header in the proxy so that one can use external + // CouchDB instances and not have the Host set to 'localhost' + var urlObj = urlLib.parse(req.url); + req.headers.host = urlObj.host; + + proxy.web(req, res); + }).listen(port); + + proxy.on('error', function (e) { + // don't explode on cancelled requests + }); + + //Remove Secure on the cookie if the proxy is communicating to a CouchDB instance + // via https. + proxy.on('proxyRes', function (proxyRes, req, res) { + if (proxyRes.headers['set-cookie']) { + proxyRes.headers['set-cookie'][0] = proxyRes.headers["set-cookie"][0].replace('Secure', ''); + } + }); + + var logo = [ + [""], + [" ______ _ "], + ["| ____| | | "], + ["| |__ __ _ _ _ __ __ | |_ ___ _ __ "], + ["| __| / _` | | | | | \\ \\/ / | __| / _ \\ | '_ \\ "], + ["| | | (_| | | |_| | > < | |_ | (_) | | | | |"], + ["|_| \\__,_| \\__,_| /_/\\_\\ \\__| \\___/ |_| |_|"], + [""] + ]; + + _.each(logo, function (line) { + console.log(line.toString()); + }); + + console.log('Listening on ' + port); +}; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f9337238/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index de0367d..7cae73b 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,20 @@ { "name": "fauxton", - "version": "0.1.0", + "version": "1.0.2", "description": "Fauxton is a modular CouchDB dashboard and Futon replacement.", - "main": "grunt.js", + "main": "./index.js", "directories": { "test": "test" }, + "bin": { + "fauxton": "./bin/fauxton" + }, "devDependencies": { + "nightwatch": "^0.6.0", + "grunt-mocha-phantomjs": "~0.3.0", + "grunt-contrib-watch": "~0.6.1" + }, + "dependencies": { "async": "~0.2.6", "couchapp": "~0.11.0", "grunt": "~0.4.1", @@ -21,17 +29,16 @@ "grunt-contrib-less": "~0.11.0", "grunt-contrib-requirejs": "~0.4.1", "grunt-contrib-uglify": "~0.2.0", - "grunt-contrib-watch": "~0.6.1", "grunt-couchapp": "~0.2.1", "grunt-exec": "~0.4.0", "grunt-init": "~0.2.0", "grunt-md5": "^0.1.11", - "grunt-mocha-phantomjs": "~0.3.0", "grunt-shell": "^1.1.1", "http-proxy": "~1.10.1", "jsxcs": "~0.2.1", + "lodash": "^3.6.0", "nano": "~5.12.0", - "nightwatch": "^0.6.0", + "optimist": "^0.6.1", "react-tools": "^0.12.0", "request": "^2.54.0", "send": "~0.1.1", @@ -46,7 +53,9 @@ "couchdb": "grunt couchdb", "couchapp": "grunt couchapp_deploy", "dev": "grunt dev", - "nightwatch": "grunt nightwatch" + "nightwatch": "grunt nightwatch", + "start": "node ./bin/fauxton", + "postinstall": "grunt release" }, "repository": { "type": "git", http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/f9337238/readme.md ---------------------------------------------------------------------- diff --git a/readme.md b/readme.md index 54f84b9..cb42175 100644 --- a/readme.md +++ b/readme.md @@ -3,6 +3,15 @@ Fauxton Fauxton is the new Web UI for CouchDB. To get it running in development on your machine. Follow the steps below. +## Install via NPM + +You can use the latest release of Fauxton via npm: + + npm install -g fauxton + fauxton + +See `fauxton --help` for extra options. + ## CouchDB is Required Install couchdb from docs here: http://couchdb.readthedocs.org/en/latest/install/index.html @@ -72,31 +81,31 @@ Refreshing the URL will re-run the tests via PhantomJS and in the browser. There is a bit of setup involved before you are able to run the Nightwatch tests. In your CouchDB admin accounts, add a user: - + > user: tester password: testerpass Then on the command line: - + npm install Start fauxton with - - grunt dev + + grunt dev And to run the tests (in another terminal tab): - + grunt nightwatch ##### Omitting nightwatch tests -If you need to omit particular tests from running you can add a `testBlacklist` option to the nightwatch section of +If you need to omit particular tests from running you can add a `testBlacklist` option to the nightwatch section of your settings.json file. That defines an object of the following form: ```javascript -// ... +// ... "nightwatch": { - // ... + // ... "testBlacklist": { "documents": ["*"], "databases": [ @@ -109,8 +118,8 @@ your settings.json file. That defines an object of the following form: ``` -The properties (`documents`, `databases`) map to a particular addon folder name (see `app/addons`). The values -should be an array of tests that you don't want to run. `*` will flag all tests from being ran, otherwise you +The properties (`documents`, `databases`) map to a particular addon folder name (see `app/addons`). The values +should be an array of tests that you don't want to run. `*` will flag all tests from being ran, otherwise you just enter the names of the files to omit. @@ -134,8 +143,6 @@ point is required for the view. Check out [writing_addons.md](writing_addons.md) for more information on writing your own addons. -## Todo Items - Want to get involved? Check out [Jira](https://issues.apache.org/jira/browse/COUCHDB/component/12320406) for a list of items to do.