ack-host
Common node hosting functionality to help reduce deployment of repetitious server functionality
Table of Contents
Examples
Simple Example
var path = var ackHost = var options = //adds ssl keys to options // create http site that relocates to httpsackHosthost80 'webapp.com' // create https server that will serve static files on www path or relocates to www pathackHosthost443 'webapp.com' options// relocate all other requests to an index //start hosting two ports 80 and 443ackHoststart
Robust Example
var path = var ackHost = var options = //adds ssl keys to options // create http server site relocates to httpsackHosthost80 'webapp.com' ackHosthost443 'webapp.com' options //start hosting two ports 80 and 443ackHoststart
Documentation
Host
Most barebones provided method of http hosting. Barely any server assumptions. Registers and returns connect app
const app = ackHosthostport host options
- Arguments
- port Number|Array-of-Numbers - port or ports to listen on
- host String|Arrray-of-String - host names to listen for requests
- options
- cert String - for ssl
- key String - for ssl
- SNICallback Function - for ssl
API
Assumes timeout of 10 seconds. A 404 will be thrown when no route is matched. Registers and returns express app
const app = ackHost
- Arguments
- port Number|Array-of-Numbers - port or ports to listen on
- host String|Arrray-of-String - host names to listen for requests
- options
- timeout Number = 10000
- cert String - for ssl
- key String - for ssl
- SNICallback Function - for ssl
Website
Assumes timeout of 30 seconds. A 404 will be thrown when no route is matched. Client input such as form data, is always pre-parsed. Registers and returns express app
const app = ackHost
- Arguments
- port Number|Array-of-Numbers - port or ports to listen on
- host String|Arrray-of-String - host names to listen for requests
- options
- timeout Number = 10000
- cert String - for ssl
- key String - for ssl
- SNICallback Function - for ssl
Express
Registers and returns express app
const app = ackHost
- Arguments
- port Number|Array-of-Numbers - port or ports to listen on
- host String|Arrray-of-String - host names to listen for requests
- options
- cert String - for ssl
- key String - for ssl
- SNICallback Function - for ssl
start
All sites registered with ack-host, will now be started
startconsole
startOnePort
Great for forcing server to start on first available port
host808080818082
Built-in Middleware
Using on of the hosting methods above (host/api/website/express), you can invoke any of the following functionality.
.secure
Relocate http to https
app
.noRobots
WHEN route matches //robots.txt$/ THEN responds with text/plain message of "User-agent: *\rDisallow: /"
app
.timeout
request timeout
app
.static
serve static client files in directory named assets
app
.cors
enable cross origin requests from all domains
app
.ignoreFavors
ignore favicon like requests
app
.compress
gzip responses where possible
app
.localNetworkOnly
Only allow local area network requests to /admin path
app
.logging
Log all requests to /admin path. Stream option not required and auto defaults to console.log aka process.stdout
app
.closeProductionErrors
if code breaks in admin path respond 500 with little info
app
.consoleNonProductionErrors
if code breaks in dev path respond 500 with a lot of info
app
.throw
throw 500 with custom message to /xxx path requests
app
.relocate
relocate one path
app
relocate all other requests to an index
app
Route Metadata
Create route explanation and defintions using GET, POST, PUT, DELETE or USE metadata.
.meta()
- details String - route descriptive details
- sample
- params Object - Key value pair to fill in path :params
- request String|Object|Array|Function - request body to be used with sample test. When Function, the function is called for its request body data
- response String|Function-Returns-String - response body to be used to fake a server response during sample testing
- test Boolean|Object
- cases Array-of-Functions|Function(response,assert)
- only Boolean
- skip Boolean
- timeout Number = 2000 - how long to wait before test is aborted
Route Metadata Example
const ackHost = const port = 3000 //create arbitrary serverconst app = ackHost app app app
Testing
Test server apps registered through ack-host
Testing Options
- port : Number = all-ports
- host : String = localhost
- method : String (GET|POST|PUT|DELETE)
- logTo : Object = console.log - not yet implemented
Large Test Example
const ackHost = const port = 3000 //create arbitrary serverconst app = ackHost app app app ackHost
Start Server and Test
Will start ack-host server and then test all defined server apps
ackHost
Test Server Already Running
Will test all defined apps against already running server
ackHost
Test Server Already Running With Limited Routes by Apps
Will test provided apps against already running server
ackHost