Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-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 1F74210AA6 for ; Tue, 5 Nov 2013 12:25:07 +0000 (UTC) Received: (qmail 82546 invoked by uid 500); 5 Nov 2013 12:25:06 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 82464 invoked by uid 500); 5 Nov 2013 12:25:06 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 82427 invoked by uid 99); 5 Nov 2013 12:25:00 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Nov 2013 12:25:00 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5D1FF3E9FB; Tue, 5 Nov 2013 12:25:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Date: Tue, 05 Nov 2013 12:25:00 -0000 Message-Id: <0d75e8925f1349d8844ff09c7412b5de@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: serve: provide basic entry point Updated Branches: refs/heads/master 95589c20c -> 733e63728 serve: provide basic entry point Index: * List included platforms (and available platforms) * List included plugins * List package name, id, version * Provide directory redirects * Implement directory browsing Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/4d44b061 Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/4d44b061 Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/4d44b061 Branch: refs/heads/master Commit: 4d44b061ff32fa026deb55a90d91bb2df5914b87 Parents: 95589c2 Author: Josh Soref Authored: Mon Nov 4 18:33:04 2013 -0500 Committer: Andrew Grieve Committed: Tue Nov 5 12:17:38 2013 +0000 ---------------------------------------------------------------------- src/serve.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4d44b061/src/serve.js ---------------------------------------------------------------------- diff --git a/src/serve.js b/src/serve.js index 9ba137c..52d478b 100644 --- a/src/serve.js +++ b/src/serve.js @@ -37,6 +37,46 @@ function launchServer(projectRoot, port) { response.write("404 Not Found\n"); response.end(); } + function do302(where) { + console.log('302 ' + request.url); + response.setHeader("Location", where); + response.writeHead(302, {"Content-Type": "text/plain"}); + response.end(); + } + function doRoot() { + response.writeHead(200, {"Content-Type": "text/html"}); + var config = new cordova_util.config_parser(path.join(projectRoot, "www/config.xml")); + response.write(""+config.name()+""); + response.write(""); + for (var c in {"name": true, "packageName": true, "version": true}) { + response.write(""); + } + response.write("

Package Metadata

"+c+""+config[c]()+"
"); + response.write("

Platforms

    "); + var installed_platforms = cordova_util.listPlatforms(projectRoot); + for (var p in platforms) { + if (installed_platforms.indexOf(p) >= 0) { + response.write("
  • "+p+"
  • \n"); + } else { + response.write("
  • "+p+"
  • \n"); + } + } + response.write("
"); + response.write("

Plugins

    "); + var pluginPath = path.join(projectRoot, 'plugins'); + var plugins = cordova_util.findPlugins(pluginPath); + for (var p in plugins) { + response.write("
  • "+plugins[p]+"
  • \n"); + } + response.write("
"); + response.write(""); + for (var c in {"name": true, "packageName": true, "version": true}) { + response.write(""); + } + response.write("

Package Metadata

"+c+""+config[c]()+"
"); + response.write(""); + response.end(); + } var urlPath = url.parse(request.url).pathname; var firstSegment = /\/(.*?)\//.exec(urlPath); if (!firstSegment) { @@ -49,7 +89,11 @@ function launchServer(projectRoot, port) { // Strip the platform out of the path. urlPath = urlPath.slice(platformId.length + 1); - var parser = new platforms[platformId].parser(path.join(projectRoot, 'platforms', platformId)); + try { + var parser = new platforms[platformId].parser(path.join(projectRoot, 'platforms', platformId)); + } catch (e) { + return do404(); + } var filePath = null; if (urlPath == '/config.xml') { @@ -59,6 +103,8 @@ function launchServer(projectRoot, port) { return; } else if (/^\/www\//.test(urlPath)) { filePath = path.join(parser.www_dir(), urlPath.slice(5)); + } else if (/^\/+[^\/]*$/.test(urlPath)) { + return do302("/" + platformId + "/www/"); } else { return do404(); } @@ -66,9 +112,30 @@ function launchServer(projectRoot, port) { fs.exists(filePath, function(exists) { if (exists) { if (fs.statSync(filePath).isDirectory()) { + index = path.join(filePath, "index.html"); + try { + if (fs.statSync(index)) { + filePath = index; + } + } catch (e) {} + } + if (fs.statSync(filePath).isDirectory()) { + if (!/\/$/.test(urlPath)) { + return do302("/" + platformId + urlPath + "/"); + } console.log('200 ' + request.url); - response.writeHead(200, {"Content-Type": "text/plain"}); - response.write("TODO: show a directory listing.\n"); + response.writeHead(200, {"Content-Type": "text/html"}); + response.write("Directory listing of "+ urlPath + ""); + response.write("

Items in this directory

"); + var items = fs.readdirSync(filePath); + response.write("
    "); + for (var i in items) { + var file = items[i]; + if (file) { + response.write('
  • '+file+'
  • \n'); + } + } + response.write("
"); response.end(); } else { var mimeType = mime.lookup(filePath);