0.1.7 • Published 11 years ago
protocolly v0.1.7
protocolly
(lazy load) Single method to create http servers, allowing you to choose between Http, Https, SPDY, Connect, Express or a mix of them.
Installation
with node:
$ npm install protocolly
Create a server
Create a standard http
server.
var protocolly = require('protocolly');
var server = protocolly('http');
server.listen(80);
Create a secure https
server.
var server = protocolly('https', {/* secure options */});
server.listen(443);
Create a secure SPDY
server.
var server = protocolly('spdy', {/* secure options */});
server.listen(443);
Create an express
server.
var server = protocolly('express');
server.get('/', function(req, res){
res.end('Hello world');
});
server.listen(80);
Create a secure express
server.
var server = protocolly('express', 'https', {/* secure options */});
Create a secure SPDY express
server.
var server = protocolly('express', 'spdy', {/* secure options */});
All combinations:
Standard
var protocolly = require('protocolly')
, server
;
// HTTP
server = protocolly();
// or
server = protocolly('http');
server = protocolly('connect'); // CONNECT
server = protocolly('express'); // EXPRESS
// and finally
server.listen();
or secure
var protocolly = require('protocolly')
, server
, fs = require('fs')
;
// Require keys if creating a secure server.
var secure = {
key: fs.readFileSync(path.join(__dirname, 'keys', 'proty.key')),
cert: fs.readFileSync(path.join(__dirname, 'keys', 'proty.crt')),
ca: fs.readFileSync(path.join(__dirname, 'keys', 'proty.pem'))
});
// HTTPS
server = protocolly('https', secure);
server = protocolly('connect', 'https', secure); // CONNECT
server = protocolly('express', 'https', secure); // EXPRESS
// SPDY
server = protocolly('spdy', secure);
server = protocolly('connect', 'spdy', secure); // CONNECT
server = protocolly('express', 'spdy', secure); // EXPRESS
server.listen();
Defaults
Set up default parameters
var protocolly = require('protocolly')
, server
;
protocolly.defaults.provider = 'express'; // default `http`
protocolly.defaults.protocol = 'spdy'; // default `http`
server = protocolly({/* secure */}); // SPDY EXPRESS
server.listen();
Using object as parameters
var protocolly = require('protocolly')
, server
;
server = protocolly({
provider: 'express',
protocol: 'spdy',
key: '..',
cert: '..',
ca: '..'
});
server.listen();
Support the old createServer
protocolly.createServer()
works just as like protocolly()
.
var protocolly = require('protocolly')
, server
;
server = protocolly.createServer('express');
server.get('/', function(req, res){
res.end('Hello world');
});
server.listen();
Exposes
Protocolly exposes all providers (lazy load) if needed.
protocolly.http
protocolly.https
protocolly.connect
protocolly.express
protocolly.spdy
Running tests
Install dev dependencies and execute tests:
$ npm install -d
$ make test
Licence
MIT