You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/07/03 17:34:44 UTC
[2/8] git commit: updated refs/heads/1846-dev-server-improvements to
038cbc9
remove express
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/8e8b8b21
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/8e8b8b21
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/8e8b8b21
Branch: refs/heads/1846-dev-server-improvements
Commit: 8e8b8b216ca8cd082ee0ae6fa27c68c0a63c380c
Parents: b9f9343
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Jul 2 12:05:44 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Tue Jul 2 12:05:44 2013 +0200
----------------------------------------------------------------------
src/fauxton/package.json | 4 +-
src/fauxton/tasks/couchserver.js | 73 ++++++++++++++++-------------------
2 files changed, 35 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/8e8b8b21/src/fauxton/package.json
----------------------------------------------------------------------
diff --git a/src/fauxton/package.json b/src/fauxton/package.json
index 5b63675..88f33bc 100644
--- a/src/fauxton/package.json
+++ b/src/fauxton/package.json
@@ -22,8 +22,8 @@
"underscore": "~1.4.2",
"url": "~0.7.9",
"urls": "~0.0.3",
- "express": "~3.0.6",
- "http-proxy": "~0.10.2"
+ "http-proxy": "~0.10.2",
+ "send": "~0.1.1"
},
"devDependencies": {},
"scripts": {
http://git-wip-us.apache.org/repos/asf/couchdb/blob/8e8b8b21/src/fauxton/tasks/couchserver.js
----------------------------------------------------------------------
diff --git a/src/fauxton/tasks/couchserver.js b/src/fauxton/tasks/couchserver.js
index b70610a..165fa44 100644
--- a/src/fauxton/tasks/couchserver.js
+++ b/src/fauxton/tasks/couchserver.js
@@ -13,18 +13,18 @@
module.exports = function (grunt) {
var log = grunt.log;
- grunt.registerTask("couchserver", 'Run a couch dev proxy server', function () {
+ 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();
+ path = require("path"),
+ http = require("http"),
+ httpProxy = require('http-proxy'),
+ send = require('send'),
+ options = grunt.config('couchserver');
// Options
- var dist_dir = options.dist || './dist/debug/';
- var app_dir = './app';
- var port = options.port || 8000;
+ var dist_dir = options.dist || './dist/debug/',
+ app_dir = './app',
+ port = options.port || 8000;
// Proxy options with default localhost
var proxy_settings = options.proxy || {
@@ -38,40 +38,35 @@ module.exports = function (grunt) {
// inform grunt that this task is async
var done = this.async();
- // serve any javascript or css files from here assets dir
- app.get(/assets/, function (req, res) {
- res.sendfile(path.join('./',req.url));
- });
-
- // serve any javascript or css files from dist debug dir
- app.get(/\.css$|\/js\/|img/, function (req, res) {
- res.sendfile(path.join(dist_dir,req.url));
- });
-
- app.get(/\.js$/, function (req, res) {
- console.log('js', req.url);
- res.sendfile(path.join(app_dir,req.url));
- });
-
// create proxy to couch for all couch requests
var proxy = new httpProxy.HttpProxy(proxy_settings);
- // serve main index file from here
- // Also proxy out to the base CouchDB host for handle_welcome_req.
- // We still need to reach the top level CouchDB host even through
- // the proxy.
- app.get('/', function (req, res) {
- var accept = req.headers.accept.split(',');
- if (accept[0] == 'application/json') {
- proxy.proxyRequest(req, res);
- } else {
- res.sendfile(path.join(dist_dir, 'index.html'));
- }
- });
+ http.createServer(function (req, res) {
+ var url = req.url,
+ accept = req.headers.accept.split(','),
+ filePath;
+
+ if (!!url.match(/assets/)) {
+ // serve any javascript or css files from here assets dir
+ filePath = path.join('./',req.url);
+ } else if (!!url.match(/\.css$|\/js\/|img/)) {
+ // serve any javascript or css files from dist debug dir
+ filePath = path.join(dist_dir,req.url);
+ } else if (!!url.match(/\.js$|\.html$/)) {
+ // server js from app directory
+ console.log('js', req.url);
+ filePath = path.join(app_dir,req.url.replace('/_utils/fauxton/app',''));
+ } else if (url === '/' && accept[0] !== 'application/json') {
+ // serve main index file from here
+ filePath = path.join(dist_dir, 'index.html');
+ };
+
+ if (filePath) {
+ return send(req, filePath).pipe(res);
+ }
- app.all('*', function (req, res) {
proxy.proxyRequest(req, res);
- });
+ }).listen(port);
// Fail this task if any errors have been logged
if (grunt.errors) {
@@ -84,8 +79,6 @@ module.exports = function (grunt) {
watch.stderr.pipe(process.stderr);
log.writeln('Listening on ' + port);
- app.listen(port);
-
});
};