diff options
author | Garren Smith <garren.smith@gmail.com> | 2013-03-16 13:42:00 +0200 |
---|---|---|
committer | Garren Smith <garren.smith@gmail.com> | 2013-03-16 13:55:24 +0200 |
commit | d2040ab43aa9a31d3442bce2cdd514003fad7e4a (patch) | |
tree | 254d5841ca6157c43b5d739b0ff3dc38854e78bb | |
parent | 57164b918f2fe8635201e37dcf5e5a3485eab50b (diff) | |
download | couchdb-d2040ab43aa9a31d3442bce2cdd514003fad7e4a.tar.gz |
add custom grunt task for couch proxy server so no need to deploy to couch while developing COUCHDB-1708
-rw-r--r-- | src/fauxton/app/initialize.js | 4 | ||||
-rw-r--r-- | src/fauxton/app/modules/databases/routes.js | 2 | ||||
-rw-r--r-- | src/fauxton/grunt.js | 172 | ||||
-rw-r--r-- | src/fauxton/package.json | 2 | ||||
-rw-r--r-- | src/fauxton/readme.md | 5 | ||||
-rw-r--r-- | src/fauxton/tasks/couchserver.js | 65 |
6 files changed, 191 insertions, 59 deletions
diff --git a/src/fauxton/app/initialize.js b/src/fauxton/app/initialize.js index 6e4a652a0..eea19d1cb 100644 --- a/src/fauxton/app/initialize.js +++ b/src/fauxton/app/initialize.js @@ -27,8 +27,8 @@ function(app, _, Bootstrap) { // The root path to run the application through. // TODO: pick this up wither at build time or from the browser root: "/_utils/fauxton/", - // Is this sufficient? - host: window.location.protocol + "//" + window.location.host, + // Firefox does not support window.location.origin so have to check first + host: (window.location.origin) ? window.location.origin : window.location.protocol + "//" + window.location.host, renderView: function(baseView, selector, view, options, callback) { baseView.setView(selector, new view(options)).render().then(callback); diff --git a/src/fauxton/app/modules/databases/routes.js b/src/fauxton/app/modules/databases/routes.js index 51ff5dbef..12edd0ea2 100644 --- a/src/fauxton/app/modules/databases/routes.js +++ b/src/fauxton/app/modules/databases/routes.js @@ -67,4 +67,4 @@ function(app, FauxtonAPI, Databases) { }; return Databases; -});
\ No newline at end of file +}); diff --git a/src/fauxton/grunt.js b/src/fauxton/grunt.js index 890d5fbe2..fa612b93a 100644 --- a/src/fauxton/grunt.js +++ b/src/fauxton/grunt.js @@ -140,7 +140,110 @@ module.exports = function(grunt) { // Create static html files from templates, for managing change of script // or css name. + template: { + couchdb:{ + src: 'assets/index.underscore', + dest: '../../share/www/fauxton/index.html', + variables: { + assets_root: '/_utils/fauxton/', + requirejs: 'require.min.js', + base: '/_utils/fauxton/' + } + }, + couchdebug:{ + src: 'assets/index.underscore', + dest: '../../share/www/fauxton/index.html', + variables: { + assets_root: '/_utils/fauxton/', + requirejs: 'require.js', + base: '/_utils/fauxton/' + } + }, + release: { + src: 'assets/index.underscore', + dest: 'dist/release/index.html', + variables: { + assets_root: '/', + requirejs: 'require.min.js', + base: '/' + } + }, + debug: { + src: 'assets/index.underscore', + dest: 'dist/debug/index.html', + variables: { + assets_root: '/', + requirejs: 'require.js', + base: '/' + } + }, + couchapp: { + src: 'assets/index.underscore', + dest: 'dist/debug/index.html', + variables: { + assets_root: '/fauxton/_design/fauxton/', + requirejs: 'require.js', + base: '/fauxton/_design/fauxton/index.html' + } + } + }, template: templateSettings, + template: { + couchdb:{ + src: 'assets/index.underscore', + dest: '../../share/www/fauxton/index.html', + variables: { + assets_root: '/_utils/fauxton/', + requirejs: 'require.min.js', + base: '/_utils/fauxton/' + } + }, + couchdebug:{ + src: 'assets/index.underscore', + dest: '../../share/www/fauxton/index.html', + variables: { + assets_root: '/_utils/fauxton/', + requirejs: 'require.js', + base: '/_utils/fauxton/' + } + }, + release: { + src: 'assets/index.underscore', + dest: 'dist/release/index.html', + variables: { + assets_root: '/', + requirejs: 'require.min.js', + base: '/' + } + }, + debug: { + src: 'assets/index.underscore', + dest: 'dist/debug/index.html', + variables: { + assets_root: '/', + requirejs: 'require.js', + base: '/' + } + }, + server: { + src: 'assets/index.underscore', + dest: 'dist/debug/index.html', + variables: { + assets_root: '/assets/', + requirejs: 'require.js', + base: '/' + } + }, + couchapp: { + src: 'assets/index.underscore', + dest: 'dist/debug/index.html', + variables: { + assets_root: '/fauxton/_design/fauxton/', + requirejs: 'require.js', + base: '/fauxton/_design/fauxton/index.html' + } + } + }, // The concatenate task is used here to merge the almond require/define // shim and the templates into the application code. It's named @@ -177,63 +280,22 @@ module.exports = function(grunt) { ] }, - // Running the server without specifying an action will run the defaults, - // port: 8000 and host: 127.0.0.1. If you would like to change these - // defaults, simply add in the properties `port` and `host` respectively. - // Alternatively you can omit the port and host properties and the server - // task will instead default to process.env.PORT or process.env.HOST. - // - // Changing the defaults might look something like this: - // - // server: { - // host: "127.0.0.1", port: 9001 - // debug: { ... can set host and port here too ... - // } - // - // To learn more about using the server task, please refer to the code - // until documentation has been written. - server: { - // Ensure the favicon is mapped correctly. - files: { "favicon.ico": "favicon.ico" }, - - debug: { - // Ensure the favicon is mapped correctly. - "index": "./dist/debug/index.html", - files: { "favicon.ico": "favicon.ico" }, - - // Map `server:debug` to `debug` folders. - folders: { - "app": "dist/debug", - "assets/js/libs": "dist/debug", - "css": "dist/debug/css", - "js": "dist/debug/js" - } - }, - - proxies: { - '': { - host: 'localhost', - port: 5984, - https: false - } - }, - - release: { - // This makes it easier for deploying, by defaulting to any IP. - host: "0.0.0.0", - - // Ensure the favicon is mapped correctly. - files: { "favicon.ico": "favicon.ico" }, - - // Map `server:release` to `release` folders. - folders: { - "app": "dist/release", - "assets/js/libs": "dist/release", - "assets/css": "dist/release" - } + // Runs a proxy server for easier development, no need to keep deploying to couchdb + couchserver: { + dist: './dist/debug/', + port: 8000, + proxy: { + host: 'localhost', + port: 5984, + https: false } }, + watch: { + files: './app/**/*', + tasks: ['debug', 'template:server'] + }, + // This task uses James Burke's excellent r.js AMD build tool. In the // future other builders may be contributed as drop-in alternatives. requirejs: { @@ -340,7 +402,7 @@ module.exports = function(grunt) { grunt.registerTask("minify", "min mincss"); // deafult task - push to CouchDB grunt.registerTask("default", "test dependencies build release install"); - grunt.registerTask("dev", "debug server:debug"); + grunt.registerTask("dev", "debug template:server couchserver"); // make a debug install grunt.registerTask("debug", "test dependencies build template copy:debug concat:debug"); // make an install that is server by mochiweb under _utils diff --git a/src/fauxton/package.json b/src/fauxton/package.json index 655cd80c1..891ea3662 100644 --- a/src/fauxton/package.json +++ b/src/fauxton/package.json @@ -9,7 +9,7 @@ "dependencies": { "async": "~0.1.22", "grunt": "~0.3.17", - "bbb": "0.1.10", + "bbb": "0.1.16", "couchapp": "0.9.1", "grunt-contrib": "~0.0.8", "grunt-contrib-copy": "~0.3.2", diff --git a/src/fauxton/readme.md b/src/fauxton/readme.md index c041735db..409296f09 100644 --- a/src/fauxton/readme.md +++ b/src/fauxton/readme.md @@ -41,6 +41,11 @@ A recent of [node.js](http://nodejs.org/) and npm is required. # Or fully compiled install # ./bin/bbb couchdb +### Dev Server + Using the dev server is the easiest way to use fauxton, specially when developing for it. + + bbb dev + ### To Deploy Fauxton ./bin/bbb couchapp_deploy - to deploy to your local [Couchdb instance] (http://localhost:5984/fauxton/_design/fauxton/index.html) diff --git a/src/fauxton/tasks/couchserver.js b/src/fauxton/tasks/couchserver.js new file mode 100644 index 000000000..9680c0006 --- /dev/null +++ b/src/fauxton/tasks/couchserver.js @@ -0,0 +1,65 @@ +module.exports = function (grunt) { + var log = grunt.log; + + grunt.registerTask("couchserver", 'Run a couch dev proxy server', function () { + var fs = require("fs"), + path = require("path"), + httpProxy = require('http-proxy'), + express = require("express"), + options = grunt.config('couchserver'), + app = express(); + + // Options + var dist_dir = options.dist || './dist/debug/'; + var port = options.port || 8000; + + // Proxy options with default localhost + var proxy_target = options.proxy || { + host: 'localhost', + port: 5984, + https: false + }; + + // inform grunt that this task is async + var done = this.async(); + + // images don't have the full path, so have to have own route for them + app.get('/img/*', function (req, res) { + res.sendfile(path.join(dist_dir,req.url)); + }); + + // serve any javascript or css files from here + app.get('/assets/*', function (req, res) { + res.sendfile(req.url.replace('/assets/',dist_dir)); + }); + + // serve main index file from here + app.get('/', function (req, res) { + res.sendfile(path.join(dist_dir, 'index.html')); + }); + + // create proxy to couch for all couch requests + var proxy = new httpProxy.HttpProxy({ + target: proxy_target + }); + + app.all('*', function (req, res) { + proxy.proxyRequest(req, res); + }); + + // Fail this task if any errors have been logged + if (grunt.errors) { + return false; + } + + var watch = grunt.util.spawn({cmd: 'bbb', grunt: true, args: ['watch']}, function (error, result, code) {/* log.writeln(String(result));*/ }); + + watch.stdout.pipe(process.stdout); + watch.stderr.pipe(process.stderr); + + log.writeln('Listening on ' + port); + app.listen(port); + + }); + +}; |