./nodejuice /path/to/directoryThis will launch both WSGI and Seeker Server. Open your browser and go to:
http://localhost:8080/some-file-name-here.htmNow you can edit *HTML* files and they will update automatically in your web browser. No need to press reload every time you make a change.
***If all you want is a simple file server, no need to read further.
var app = exports; app.journey = function( request, response ) { response.impress( '/templates/index.htm', { dynamic : 'my text here' } ); };
// FILE: nodejuice.js exports.sidekick = { host : null, // Leave 'null' to listen on all hosts. port : 8010, // access your server from this port. fetch : { // point to your web server. host : 'localhost', // point to your web server. port : 8080 // point to your web server. } }; exports.seeker = { host : null, // Leave 'null' to listen on all hosts. port : 8002, delay : 200, // milliseconds before page starts to reload. // setting too low will cause apahce read file error. wait : 1500, // milliseconds before a new connection. // setting this too low will make crazziness. add : true, // allow new file to push updates. remove : true, // allow file delete to push updates. touch : false, // allow file touch to push updates. access : false, // allow file reads to push updates. bits : true, // allow chmod/chown to push updates. save : true, // allow file save to push updates. dir : true, // allow directory changes to push updates. ignore : [ /git$/, /svn$/, /cvs$/, /swp$/, /~$/ ] // stuff to ignore. }; exports.wsgi = { host : null, // Leave 'null' to listen on all hosts. port : 8080, root : 'index.htm', // used for static content as the default. retry : { max: 4, wait: 120 }, // number of retries to load a file. url : [ // interface between browser URL Request and Files. [/^\/app$/, '/app.js'], // run an application. [/^\/.*/, '/static/'], // serve content from /static/ dir. [/^\/.*/, '/'] // server static content from root app dir. ] };
var app = exports; app.journey = function( response, request ) { // your code here... };
response.attack( body, // Delivery HTML, Text or Binary [code], // OPTIONAL: HTTP 3-Digit Code (200, 404, 500, etc.) [type], // OPTIONAL: "Content-Type" "text/html" "text/plain" [headers], // OPTIONAL: HTTP Headers [encoding] // OPTIONAL: "utf8" or "binary" the default is "utf8" );
// Example Use of response.attack() var app = exports; app.journey = function( request, response ) { response.attack( 'hello!', // text (body) 200, // response code 'text/html', // content type. {}, // headers empty for no specail reason. "utf8" // encoding ); };
response.impress( file, // point the the file relative to your application directory. [object] // OPTIONAL: Will find all {{tags}} and impress data in place. );
// Example Use of response.impress() var app = exports; app.journey = function( request, response ) { response.impress( '/templates/index.htm', { food : 'apple' } ); };Also available is response.utility.impress( file, args, callback );
response.utility.noble( file, // /path/to/file/name success // function( type, body, encoding ) callback on load. [fail] // OPTIONAL: callback on failure. );
// Example Use of response.utility.noble() var file = response.appdir + '/templates/index.htm'; response.utility.noble( file, function( type, body, encoding ) { // Send File to Browser response.attack( body, 200, type, {}, encoding ); }, function() { // Send Error response['404']( request, response, file ); } );
response.utility.supplant( text, // string of chars to update. object // Will find all {{tags}} and impress data in place. );
// Example Use of response.utility.supplant() var parsed_text = response.utility.supplant( // Parses as "Hello Frank Alphabet!" "Hello {{name}}!", { name : "Frank Alphabet" } );
response.utility.inform( object // What is to be logged. );
// Example Use of response.utility.inform() var util = response.utility; // Print to terminal: { timestamp: 1262558727644, some_text: "log this" } util.inform({ timestamp : util.earliest(), some_text : 'log this' });
response.utility.recurse( start, // Starting Directory ignore, // Array of regexs to ignore matching files/directories. callback // function(file) called EVERY TIME a File or Directory is found. );
// Example Use of response.utility.recurse() // Stream a list of files to the web browser: response.sendHeader( 200, { "Content-Type" : "text/plain" } ); response.utility.recurse( response.appdir + '/static', [ /.git$/, /csv$/, /.svn$/, /pants/ ], function(file) { response.sendBody( file + "\n", "utf8" ); } ); // Only allow 1 second of data streaming. setTimeout( function() {response.finish()}, 1000 );
response.utility.fetch({ port, // 80 host, // "www.google.com" type, // "GET" or "POST" or "HEAD" path, // "/" or "/index.htm" or "/someurl" headers, // { "Accept-Encoding" : "utf8" } body, // "binary, text or POST data" encoding, // "binary" or "utf8" ready, // function (response) {} when connection is made good, // function ( chunk, response, encoding ) {} chunck recieved. fail, // function ( chunk, response, encoding ) {} failure occurs. finished // function ( final, response, encoding ) {} all is done. })
// Example Use of response.utility.fetch() response.utility.fetch({ port : 80, host : "www.google.com", type : "GET", path : "/", finished : function( data, res, encoding ) { // Proxy google's home page to browser. response.attack( data, 200, res.headers['content-type'], {}, encoding ) } })
response.utility.earliest();
// Example Use of response.utility.earliest() var timestamp = response.utility.earliest();