Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix

  • Loading branch information...
commit 72562f134f24d801f5125eece64b2679bd4f5400 1 parent ded961c
@digplan authored
View
135 README.md
@@ -1,41 +1,66 @@
####Quick-Server
-Is a small web server stub for NodeJS/Express/Hogan and can be run directly or require'd into a script.
-Uses Express, Hogan templates, allows you to set port, catch errors, app path, statics the current directory, without all the boilerplate.
+Is web server helper for NodeJS/Express/Hogan and can be run directly or require'd into a script.
+Its for doing stuff, without all the boilerplate.
-By default apppath is the current directory. All server-*.js files will be required in. These are modules for the server. All files in the apppath are static served also.
-
-###Global install
+###Install
````
+$ npm install quick-server
+OR
$ npm install quick-server -g
$ quick-server
````
-###Run script directly
-````
-$ node ./quick-server.js
+###Require into a script - all params are optional
+````
+require('quick-server')({
+ port: 4000,
+ ip:'127.0.0.1',
+ session:'mysesskey',
+ errors: 1,
+ ssl:'myhost.com',
+ logport: 8081,
+ debug: 1
+}, function(app){
+ console.log(app.debug);
+})
````
-###Require into a script
+###Use env instead of options
````
-require('quick-server')({port: 4000, debug: 1}, function(app){
+test.js --
+require('quick-server')(null, function(app){
console.log(app.debug);
})
+
+$ port=81 node test.js
````
-####Hogan rendering
+####Hogan/Mustache.js rendering
````
app.hogan(template_filename, obj) --OR--
res.render(template_filename, obj)
````
-####Return NodeJS style error/results object
+####s.return
````
-res.return(null, {name:'quicker'});
+// Return NodeJS style error/results object to browser
- to browser ==> {e:null, {r: {name:'quicker'}}}
+app.get('/api/name', function(r, s){
+ s.return(null, {name: 'quicker'});
+})
+ ** to browser ==> {e:null, {r: {name:'quicker'}}}
+````
+
+####s.render
````
+// Takes file name or string as a template
-Experimental support for partials..
+app.get('/', function(r, s){
+ s.render('Hi {{name}}', {name: 'there'});
+})
+````
+
+####Experimental support for partials..
index.html
````
Hi there {{>part.html}}
@@ -59,23 +84,79 @@ module.exports = function(options, app){
$ session=mysecretisthis quick-server
````
-###Options
+###SSL
````
-$ debug=1 errors=1 apppath=./myapppath port=8080 quick-server
+$ ssl=mydomain.com quick-server
-// debug prints app info to console when starting
-// errors will set node to catch all uncaught application errors
-// port sets the HTTP port, 80 by default, 443 for SSL
-// ip sets the IP address to use, 127.0.0.1 by default
-// apppath specifies a directory to auto load modules (server-*.js) and serve static files
+OR
-// https server
-````
-$ ssl=mydomain.com quick-server
+Two steps to run as SSL/HTTPS server:
-Put files in the current directory:
+1)
+require('quick-server')({ssl: 'mydomain.com'}, function(options, app){
+ ...
+}
+
+2)
+Put these files in the current directory:
mydomain.com.key
-mydomain.com.intermediate.crt
+mydomain.com.intermediate.crt (called gd_bundle if gotten from GoDaddy)
mydomain.com.cert
````
+
+###Logging in browser
+````
+require('quick-server')({ logport: 8081 }, function(app){
+ ...
+})
+
+// In HTML
+<script src='/log'></script>
+
+log(); // Server Console.Log is now websocketed to the browser
+ // view in the browser console
+logstop(); // Stop that
+
+````
+
+###Browser JS
+````
+// In HTML
+
+// JQuery, Bootstrap JS, and the helpers below
+<script src='/j.js'></script>
+
+// localStorage helpers
+_localStorage.set = function(n, o)
+_localStorage.get = function(n)
+_localStorage.array = function(n, f, p)
+
+// client-side Mustache rendering
+_render(template, object, callback)
+
+// time helper
+_time(); dosomething(); _time(); // displays time it takes to dosomething
+
+// Websocket client - server should send node style {e: error, r: result}
+_ws('ws://localhost:8081', function(e, r){
+ if(e) throw(e);
+ console.log(r);
+})
+
+// POST - quick-server s.returns node style error, results
+_post = function(url, data, function(e, r){
+ if(e) throw(e);
+ ...
+})
+
+// JQuery helpers
+
+<div id='mydiv'></div>
+
+$('#mydiv').render('Hello {{name}}', {name: 'there'})
+
+.renderLocal('Hello {{name}}') // localStorage key mydiv = {name: 'there'}
+.renderPost('Hello {{name}}', 'http://localhost/api/getsometh', {value: 'name'})
+.renderSocket('Hello {{name}}', 'ws://localhost:8081') // socket gets object and renders to templ
+````
View
17 logger/logger.js
@@ -0,0 +1,17 @@
+module.exports = function(options, app){
+ options = options || {};
+ options.port = options.port || 8080;
+
+ app.get('/log', function(r, s){
+ s.send('var _wsl;logstop=function(){_wsl.close()};log=function(){_wsl=new WebSocket("ws://localhost:'+options.port+'");_wsl.onmessage=function(m){console.log(m.data)}}');
+ })
+
+ var svr = require('socket-server')({port: options.port});
+ console.log = (function(of){
+ return function(s){
+ svr.sendAll(s);
+ of(s);
+ }
+ })(console.log)
+
+}
View
9 logger/test.js
@@ -0,0 +1,9 @@
+require('quick-server')(null, function(o, a){
+ require('./logger.js')(o, a);
+
+ a.get('/', function(r, s){
+ s.end('<script src="/log"></script>')
+ })
+
+ setInterval(function() { console.log('ok ok') }, 1000);
+})
View
4 package.json
@@ -18,7 +18,7 @@
"express": "",
"colors": "",
"hogan.js": "",
- "passport": "",
+ "socket-server": "",
"underscore": ""
},
"repository": {
@@ -28,5 +28,5 @@
"bin": {
"quick-server": "quick-server.js"
},
- "version": "0.4.10"
+ "version": "0.5.0"
}
View
35 quick-server.js
@@ -12,7 +12,6 @@ function start(options, fn){
, debug.requiremainfilename = require.main.filename
, debug.templates = apppath;
-
// static current dir
app.use('/', express.static(debug.static = apppath));
app.use(express.bodyParser());
@@ -96,24 +95,24 @@ function start(options, fn){
})
}
- if(options.ssl){
- opts = {
- key: fs.readFileSync('./'+options.ssl+'.key').toString(),
- cert: fs.readFileSync('./'+options.ssl+'.crt').toString(),
- ca: fs.readFileSync('./'+options.ssl+'.intermediate.crt').toString()
+ if(options.ssl){
+ opts = {
+ key: fs.readFileSync('./'+options.ssl+'.key').toString(),
+ cert: fs.readFileSync('./'+options.ssl+'.crt').toString(),
+ ca: fs.readFileSync('./'+options.ssl+'.intermediate.crt').toString()
+ }
+ var server = require('https').createServer(opts, app).listen(443, function(){
+ console.log('listening on', JSON.stringify(server.address()).green);
+ })
+ debug.ssl = options.ssl;
+ } else {
+ var server = http.createServer(app).listen(debug.port = port, debug.ip = ip, function(){
+ console.log('listening on', JSON.stringify(server.address()).green);
+ })
}
- var server = require('https').createServer(opts, app).listen(443, function(){
- console.log('listening on', JSON.stringify(server.address()).green);
- })
- debug.ssl = options.ssl;
- } else {
- var server = http.createServer(app).listen(debug.port = port, debug.ip = ip, function(){
- console.log('listening on', JSON.stringify(server.address()).green);
- })
- }
- if(options.debug) console.log(JSON.stringify(debug, null, 4));
-
- if(fn) fn(options, app);
+ if(options.debug) console.log(JSON.stringify(debug, null, 4));
+ if(options.logport) require('./logger/logger.js')({port: options.logport}, app);
+ if(fn) fn(options, app);
}
__filename !== require.main.filename ? module.exports = start : start();
View
2  test/index.html
@@ -1,4 +1,6 @@
<script src='j.js'></script>
+<script src='log'></script>
+
<link rel='stylesheet' href='http://tiny.cc/bootstrapcss'/>
<div id='testdiv'></div>
View
7 test/test.js
@@ -1,4 +1,4 @@
-require('../quick-server.js')({port: 80, debug: 0}, function(options, app){
+require('../quick-server.js')({port: 80, logport: 8081}, function(options, app){
/*
require('appcache-node')({files:[
'j.js', 'http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css'
@@ -30,5 +30,8 @@ require('../quick-server.js')({port: 80, debug: 0}, function(options, app){
var sock = require('socket-server')({port:8080});
var obj = {e: null, r:{some:'thing'}};
- setInterval(function(){ sock.sendAll(obj) }, 3000);
+
+ setInterval(function(){ sock.sendAll(obj) }, 5000);
+
+ setInterval(function(){ console.log('log from server OK') }, 4000);
})
Please sign in to comment.
Something went wrong with that request. Please try again.