web-app-runner
Advanced tools
Comparing version 0.90.23 to 0.90.24
@@ -7,2 +7,4 @@ /** | ||
var Logger = require('simple-node-logger' ); | ||
module.exports.readConfig = function() { | ||
@@ -12,3 +14,3 @@ var config = { | ||
port:3005, | ||
logfile: process.env.HOME + '/logs/app-start.log', | ||
log: Logger.createSimpleFileLogger( process.env.HOME + '/logs/staging-3005.log'), | ||
daemon:true | ||
@@ -15,0 +17,0 @@ }; |
#!/usr/bin/env node | ||
var opts = { | ||
port:3006, | ||
logfile: __dirname + '/app-start.log', | ||
daemon:true, | ||
env:'production' | ||
}; | ||
var conf = require( __dirname + '/conf' ); | ||
require('../lib/WebAppRunner').createInstance( opts ); | ||
require('../lib/WebAppRunner').createInstance( { configFile:conf } ); |
#!/usr/bin/env node | ||
// example of how to create a daemon server without setting the daemon flag | ||
var dash = require( 'lodash' ), | ||
childKey = '--run-child-service', | ||
args = dash.toArray( process.argv ), | ||
@@ -11,5 +13,6 @@ runner, | ||
env:'staging', | ||
daemon:true | ||
daemon:false | ||
}; | ||
// remove the 'node' param | ||
args.shift(); | ||
@@ -19,9 +22,16 @@ | ||
if (args[ 1 ] === 'runDaemon') { | ||
if (args[ 1 ] === childKey ) { | ||
// this was called by the background service, so run as a child | ||
console.log( 'run the web app, pid: ', process.pid ); | ||
runner = require( '../lib/WebAppRunner' ).createInstance( opts ); | ||
runner.start(); | ||
} else { | ||
command = args[ 0 ]; | ||
// pull the original script name | ||
command = args.shift(); | ||
// push our child key to the front of the args list, while preserving any other args | ||
args.unshift( childKey ); | ||
runner = require('background-service-runner' ).createDaemonRunner(); | ||
child = runner.start( command, [ 'runDaemon' ] ); | ||
child = runner.start( command, args ); | ||
@@ -28,0 +38,0 @@ console.log('child pid: ', child.pid ); |
@@ -110,6 +110,16 @@ /** | ||
var runner; | ||
var runner, | ||
conf; | ||
if (!opts) opts = {}; | ||
if (!opts) { | ||
opts = {}; | ||
} else if (opts.configFile) { | ||
conf = opts.configFile; | ||
opts = conf.readConfig(); | ||
// assign the dynamic reader if available | ||
opts.readFilters = conf.readFilters; | ||
} | ||
if (!opts.log) { | ||
@@ -116,0 +126,0 @@ if (opts.logfile) { |
{ | ||
"name": "web-app-runner", | ||
"version": "0.90.23", | ||
"version": "0.90.24", | ||
"description": "A simple HTTP application server that accepts or rejects connections based on authenticated attributes including ip, user agent, etc. The server can be used stand alone or as middleware for connect or express.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -20,13 +20,31 @@ # Web App Runner | ||
### Basic Web Server | ||
### Minimal Web Server | ||
A minimal server running on port 3000 from a root public folder that has index.html: | ||
// by default the server returns public/index.html | ||
var runner = require('web-app-runner').createInstance(); | ||
require('web-app-runner').createInstance().start(); | ||
runner.start(); | ||
### Basic Server | ||
Adding options and middleware gives you a bit more flexibility: | ||
var opts = {}, | ||
runner; | ||
opts.port = 3002; | ||
opts.env = 'staging'; | ||
opts.home = './'; | ||
runner = require('web-app-runner').createInstance( opts ); | ||
runner.createApp().use( someMiddleWare() ); | ||
runner.start(); | ||
### Production Web Server | ||
This example shows a more realistic environment where the environment is set to production, configuration is read from a file and the server runs as a cluster of services in a background daemon. | ||
#### Static Configuration Example | ||
This example shows a more realistic environment where the environment is set to production, configuration is set int the run script and the server runs in a background daemon. | ||
// IP & agent accept/reject lists defined in config | ||
@@ -54,2 +72,21 @@ var configFile = __dirname + '/config.js', | ||
The advantage to this approach is that it exposes the connect 'app', allowing you to use additional middleware. The disadvantage is that the script is static, so can't be re-read while the service is running. | ||
#### Dynamic Configuration Example | ||
This example separates configuration into a re-readable configuration file. | ||
require('web-app-runner').createInstance( { configFile: __dirname + '/conf.js' } ); | ||
The advantage to this approach is that running a server is a one-liner. So, to run two or three servers is as easy as this: | ||
var conf = __dirname + '/conf.js', | ||
ports = [ 3001, 3002, 3003 ]; | ||
keys.forEach(function(port) { | ||
require('web-app-runner').createInstance( { configFile:conf, port:port } ); | ||
}); | ||
Each server has its own process id and can be started/stopped independent of the other servers. | ||
### IP Filter | ||
@@ -114,5 +151,21 @@ | ||
// or | ||
make watch | ||
// or | ||
make jshint | ||
## Examples | ||
There are a number of simple and not so simple examples in the examples folder that demonstrate how to run in development and production mode. The examples include: | ||
* basic-server.js | ||
* ipfilter-server.js | ||
* daemon-server.js | ||
There is also a more realistic production runner in the bin folder called bin/start.js that includes a conf.js file. | ||
- - - | ||
<p><small><em>Copyright © 2014, rain city software | Version 0.90.23</em></small></p> | ||
<p><small><em>Copyright © 2014, rain city software | Version 0.90.24</em></small></p> |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
29084
22
649
169
3