Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 906b29f5874379d8a66c4858d7302619f1690cee @tj committed Jun 24, 2011
Showing with 168 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 .npmignore
  3. +5 −0 History.md
  4. +44 −0 Readme.md
  5. +102 −0 bin/serve
  6. +10 −0 package.json
@@ -0,0 +1,3 @@
+.DS_Store
+node_modules
+*.sock
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
@@ -0,0 +1,44 @@
+
+# serve
+
+ Simple command-line file / directory server built with connect.
+
+## Installation
+
+ $ npm install -g serve
+
+## Usage
+
+ Usage: serve [options] [dir]
+
+ Options:
+
+ -L, --no-logs disable logging
+ -D, --no-dirs disable directory serving
+ -p, --port <port> specify the <port>, defaults to 3000
+ -h, --help show usage information
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
102 bin/serve
@@ -0,0 +1,102 @@
+#!/usr/bin/env node
+
+/**
+ * Arguments.
+ */
+
+var args = process.argv.slice(2);
+
+/**
+ * Default port.
+ */
+
+var port = 3000;
+
+/**
+ * Default path to serve.
+ */
+
+var path = process.cwd();
+
+/**
+ * Use directory listings.
+ */
+
+var directory = true;
+
+/**
+ * Use logging with optional path.
+ */
+
+var log = true;
+
+/**
+ * Module dependencies.
+ */
+
+var connect = require('connect');
+
+/**
+ * Usage information.
+ */
+
+var usage = [
+ ''
+ , ' Usage: serve [options] [dir]'
+ , ''
+ , ' Options:'
+ , ''
+ , ' -L, --no-logs disable logging'
+ , ' -D, --no-dirs disable directory serving'
+ , ' -p, --port <port> specify the <port>, defaults to 3000'
+ , ' -h, --help show usage information'
+ , ''
+].join('\n');
+
+/**
+ * Required argument.
+ */
+
+function required() {
+ if (args.length) return args.shift();
+ console.error(' %s requires an argument', arg);
+ process.exit(1);
+}
+
+// parse arguments
+
+var arg;
+while (args.length) {
+ switch (arg = args.shift()) {
+ case '-h':
+ case '--help':
+ console.log(usage);
+ process.exit(0);
+ break;
+ case '-L':
+ case '--no-logs':
+ log = false;
+ break;
+ case '-D':
+ case '--no-dirs':
+ directory = false;
+ break;
+ case '-p':
+ case '--port':
+ port = Number(required());
+ break;
+ default:
+ path = arg;
+ }
+}
+
+// setup the server
+
+var server = connect();
+
+server.use(connect.favicon());
+if (log) server.use(connect.logger());
+server.use(connect.static(path));
+if (directory) server.use(connect.directory(path));
+server.listen(port);
+console.log(' serving %s on port %d', path, server.address().port);
@@ -0,0 +1,10 @@
+{
+ "name": "serve"
+ , "version": "0.0.1"
+ , "description": "Simple command-line file / directory server build owith connect"
+ , "keywords": []
+ , "author": "TJ Holowaychuk <tj@vision-media.ca>"
+ , "dependencies": { "connect": "1.5.x" }
+ , "main": "index"
+ , "engines": { "node": "0.4.x" }
+}

0 comments on commit 906b29f

Please sign in to comment.