Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 4aa955e37b68171197abb4562fed76dc4f76ed3f @baryshev committed Aug 11, 2012
Showing with 87 additions and 0 deletions.
  1. +1 −0 .npmignore
  2. +22 −0 LICENSE
  3. +31 −0 README.md
  4. +1 −0 index.js
  5. +19 −0 lib/connect-domain.js
  6. +13 −0 package.json
@@ -0,0 +1 @@
+.git*
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2012 Vadim M. Baryshev <vadimbaryshev@gmail.com>
+
+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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
+# About
+
+Asynchronous error handler for Connect
+
+# Installation
+
+ npm install connect-domain
+
+# Usage
+
+```js
+var
+ connect = require('connect'),
+ connectDomain = require('connect-domain');
+
+var app = connect()
+ .use(connectDomain(function(err, req, res) {
+ res.end(err.message);
+ }))
+ .use(function(req, res){
+ setTimeout(function() {
+ if (Math.random() > 0.5) {
+ throw new Error('Error from timeout');
+ } else {
+ res.end('Hello from Connect!');
+ }
+ }, 1000);
+ });
+
+app.listen(3000);
+```
@@ -0,0 +1 @@
+module.exports = require('./lib/connect-domain');
@@ -0,0 +1,19 @@
+var domain = require('domain');
+
+exports = module.exports = function(handler) {
+ return function(req, res, next) {
+ var reqDomain = domain.create();
+
+ reqDomain.on('error', function(err) {
+ res.on('close', function() {
+ reqDomain.dispose();
+ });
+ if (handler && typeof handler === 'function') {
+ handler(err, req, res);
+ }
+ });
+
+ reqDomain.enter();
+ next();
+ };
+};
@@ -0,0 +1,13 @@
+{
+ "name" : "connect-domain",
+ "version" : "0.1.0",
+ "description" : "Asynchronous error handler for Connect",
+ "keywords": [ "domain", "error", "connect" ],
+ "author" : "Vadim M. Baryshev <vadimbaryshev@gmail.com>",
+ "main" : "index",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/baryshev/connect-domain.git"
+ },
+ "engines" : { "node": ">= 0.8.0" }
+}

0 comments on commit 4aa955e

Please sign in to comment.