Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (43 sloc) 1.56 KB
#!/usr/bin/env node
var argv = require('optimist').argv;
var server = require('../crud-file-server');
if(!argv.q) {
console.log('usage:');
console.log(' crud-file-server [options]');
console.log('');
console.log('this starts a file server using the specified command-line options');
console.log('');
console.log('options:');
console.log('');
console.log(' -f file system path to expose over http');
console.log(' -h log head requests');
console.log(' -m vpath to use the mount the faye server (omit to disable publication)');
console.log(' -p port to listen on (example, 80)');
console.log(' -q suppress this message');
console.log(' -r read only');
console.log(' -v virtual path to host the file server on');
console.log('');
console.log('example:');
console.log('');
console.log(' crud-file-server -f c:/ -p 8080 -q -m /faye -v filez');
console.log('');
}
var port = argv.p || 80;
var path = argv.f || process.cwd();
var vpath = (argv.v || '').trimLeft();
var readOnly = argv.v;
var logHeadRequests = argv.h;
var publish = function() {};
if(argv.m) {
var faye = require('faye');
var server = new faye.NodeAdapter({mount: argv.m});
console.log('faye server listening on ' + argv.p);
server.listen(argv.p);
publish = function(message) {
server.publish('/', message);
};
}
require('http').createServer(function (req, res) {
server.handleRequest(vpath, path, req, res, fayeServer, readOnly, logHeadRequests);
}).listen(port);
console.log('listening on :' + port + '/' + vpath + ', serving ' + path);
Something went wrong with that request. Please try again.