Comparing version 0.3.3 to 0.3.4
@@ -22,3 +22,3 @@ var fs = require('fs'), | ||
router.get('/foo', function () { | ||
this.res.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
this.res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
this.res.end('hello world\n'); | ||
@@ -41,4 +41,12 @@ }); | ||
router.get('/redirect', function() { | ||
this.res.redirect('http://www.google.com'); | ||
}); | ||
router.get('/custom_redirect', function() { | ||
this.res.redirect('/foo', 301); | ||
}); | ||
server.listen(9090); | ||
console.log('union with director running on 9090'); | ||
/* | ||
* core.js: Core functionality for the Flatiron HTTP plugin. | ||
* core.js: Core functionality for the Flatiron HTTP (with SPDY support) plugin. | ||
* | ||
@@ -53,16 +53,40 @@ * (C) 2011, Nodejitsu Inc. | ||
if (options.https) { | ||
if (!options.https.key || !options.https.cert) { | ||
throw new Error('Both `options.https.key` and `options.https.cert` are required.'); | ||
// | ||
// both https and spdy requires same params | ||
// | ||
if (options.https || options.spdy) { | ||
if(options.https && options.spdy){ | ||
throw new Error('You shouldn\'t be using https and spdy simultaneously.') | ||
} | ||
var key, serverOptions, credentials; | ||
if(options.spdy) { | ||
key = 'spdy'; | ||
} else { | ||
key = 'https'; | ||
} | ||
serverOptions = options[key]; | ||
if (!serverOptions.key || !serverOptions.cert) { | ||
throw new Error('Both options.'+key+'.`key` and options.'+key+'.`cert` are required.'); | ||
} | ||
credentials = { | ||
key: fs.readFileSync(options.https.key), | ||
cert: fs.readFileSync(options.https.cert) | ||
key: fs.readFileSync(serverOptions.key), | ||
cert: fs.readFileSync(serverOptions.cert) | ||
}; | ||
if (options.https.ca) { | ||
credentials.ca = fs.readFileSync(options.https.ca); | ||
if (serverOptions.ca) { | ||
credentials.ca = fs.readFileSync(serverOptions.ca); | ||
} | ||
if(options.spdy){ | ||
// spdy is optional so we require module here rather than on top | ||
var spdy = require('spdy'); | ||
return spdy.createServer(credentials, requestHandler); | ||
} | ||
return https.createServer(credentials, requestHandler); | ||
@@ -69,0 +93,0 @@ } |
@@ -162,1 +162,18 @@ /* | ||
}; | ||
ResponseStream.prototype.redirect = function(path, status) { | ||
var url = ''; | ||
if(~path.indexOf('://')) { | ||
url = path; | ||
} else { | ||
url += this.req.connection.encrypted ? 'https://' : 'http://'; | ||
url += this.req.headers.host; | ||
url += (path[0] === '/') ? path : '/' + path; | ||
} | ||
this.res.writeHead(status || 302, { | ||
'Location': url | ||
}); | ||
this.res.end(); | ||
}; |
{ | ||
"name": "union", | ||
"description": "A hybrid buffered / streaming middleware kernel backwards compatible with connect.", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"author": "Nodejitsu Inc. <info@nodejitsu.com>", | ||
@@ -16,3 +16,3 @@ "maintainers": [ | ||
"pkginfo": "0.2.x", | ||
"qs": "0.4.x" | ||
"qs": "0.5.x" | ||
}, | ||
@@ -19,0 +19,0 @@ "devDependencies": { |
@@ -33,4 +33,3 @@ | ||
union = require('../lib'), | ||
director = require('director'), | ||
favicon = require('./middleware/favicon'); | ||
director = require('director'); | ||
@@ -41,3 +40,2 @@ var router = new director.http.Router(); | ||
before: [ | ||
favicon('./favicon.png'), | ||
function (req, res) { | ||
@@ -121,2 +119,4 @@ var found = router.dispatch(req, res); | ||
### SPDY enabled server example | ||
# API | ||
@@ -155,2 +155,6 @@ | ||
@option spdy {Object} | ||
(optional) A value that specifies the certificate and key necessary to create an instance of | ||
`spdy.Server`. | ||
@option headers {Object} | ||
@@ -176,11 +180,9 @@ (optional) An object representing a set of headers to set in every outgoing response | ||
An example of the `https` option. | ||
An example of the `https` or `spdy` option. | ||
``` js | ||
{ | ||
https: { | ||
cert: 'path/to/cert.pem', | ||
key: 'path/to/key.pem', | ||
ca: 'path/to/ca.pem' | ||
} | ||
cert: 'path/to/cert.pem', | ||
key: 'path/to/key.pem', | ||
ca: 'path/to/ca.pem' | ||
} | ||
@@ -253,3 +255,3 @@ ``` | ||
## HttpStream Instance Memebers | ||
## HttpStream Instance Members | ||
@@ -319,3 +321,3 @@ ### url | ||
Copyright (c) 2010 Nodejitsu Inc. <http://www.twitter.com/nodejitsu> | ||
Copyright (c) 2010-2012 Nodejitsu Inc. <http://www.twitter.com/nodejitsu> | ||
@@ -322,0 +324,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
@@ -51,2 +51,26 @@ /* | ||
} | ||
}, | ||
"a GET request to `/redirect`": { | ||
topic: function() { | ||
request.get({ | ||
url: 'http://localhost:9090/redirect', | ||
followRedirect: false | ||
}, this.callback); | ||
}, | ||
"it should redirect to `http://www.google.com`": function(err, res, body) { | ||
assert.equal(res.statusCode, 302); | ||
assert.equal(res.headers.location, "http://www.google.com"); | ||
} | ||
}, | ||
"a GET request to `/custom_redirect`": { | ||
topic: function() { | ||
request.get({ | ||
url: 'http://localhost:9090/custom_redirect', | ||
followRedirect: false | ||
}, this.callback); | ||
}, | ||
"it should redirect to `/foo`": function(err, res, body) { | ||
assert.equal(res.statusCode, 301); | ||
assert.equal(res.headers.location, "http://localhost:9090/foo"); | ||
} | ||
} | ||
@@ -53,0 +77,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
55731
32
1172
325
0