Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[major] Nuke domains

  • Loading branch information...
commit 93f52cc1474c0ee452b274be77d635d3c1f3bbcb 1 parent b90a9a4
@3rd-Eden 3rd-Eden authored
View
3  README.md
@@ -92,9 +92,6 @@ BigPipe server. The following options are supported:
- **dist** The location of our folder where we can store our compiled CSS and
JavaScript to disk. If the path or folder does not exist it will be
automatically created. Defaults to `working dir/dist`.
-- **domain** Use Node's domains when processing requests so errors are handled
- by BigPipe. Defaults to `true` if domains are supported, `false` if domains
- are not supported.
- **pages** A directory that contains your Page definitions or an array of Page
constructors. Defaults to `working dir/dist`. If you don't provide Pages it
will serve a 404 page for every request.
View
51 index.js
@@ -12,15 +12,6 @@ var debug = require('diagnostics')('bigpipe:server')
, fs = require('fs');
//
-// Try to detect if we've got domains support. So we can easily serve 500 error
-// pages when we have an error.
-//
-var domain;
-
-try { domain = require('domain'); }
-catch (e) {}
-
-//
// Automatically add trailers support to Node.js.
//
var trailers = require('trailers');
@@ -64,7 +55,6 @@ function configure(obj) {
*
* - cache: A object were we store our URL->page mapping.
* - dist: The pathname for the compiled assets.
- * - domain: Use domains to handle requests.
* - pages: String or array of pages we serve.
* - parser: Which parser should be used to send data in real-time.
* - pathname: The pathname we use for Primus requests.
@@ -87,7 +77,6 @@ function Pipe(server, options) {
//
// Constants and properties that should never be overridden.
//
- readable('domains', !!options('domain', domain)); // Use domains for each req.
readable('statusCodes', Object.create(null)); // Stores error pages.
readable('cache', options('cache', false)); // Enable URL lookup caching.
readable('plugins', Object.create(null)); // Plugin storage.
@@ -564,7 +553,6 @@ Pipe.readable('pluggable', function pluggable(plugins) {
/**
* Dispatch incoming requests.
*
- * @TODO cancel POST requests, when we don't accept them
* @param {Request} req HTTP request.
* @param {Response} res HTTP response.
* @returns {Pipe} fluent interface
@@ -574,38 +562,29 @@ Pipe.readable('dispatch', function dispatch(req, res) {
var pipe = this;
/**
- * We've found a matching route, process the page.
+ * Something failed while processing things. Display an error page.
*
- * @param {Error} err We've encountered an error while generating shizzle.
- * @param {Page} page The page instance.
+ * @param {String}
* @api private
*/
- function completed(err, page) {
- res.once('close', page.emits('close'));
+ function fivehundered(err) {
+ var page = new pipe.statusCodes[500](pipe);
- if (pipe.domains) {
- page.domain = domain.create();
+ //
+ // Set an error as data so it can be used as data in the template.
+ //
+ page.data = err;
+ page.configure(req, res);
+ }
- page.domain.on('error', function (err) {
- debug('%s - %s received an error while processing the page, captured by domains: %s', page.method, page.path, err.stack);
+ return this.forEach(req, res, function next(err) {
+ if (err) return fivehundered(err);
- try { page.end(err); } catch (e) {
- console.error(e.stack);
- }
- });
+ pipe.router(req, res, function completed(err, page) {
+ if (err) return fivehundered(err);
- page.domain.run(function run() {
- debug('running page %s inside a domain', page.path);
- page.configure(req, res);
- });
- } else {
- debug('running page %s outside a domain', page.path);
page.configure(req, res);
- }
- }
-
- return this.forEach(req, res, function next() {
- pipe.router(req, res, completed);
+ });
});
});
View
3  page.js
@@ -502,8 +502,6 @@ Page.readable('end', function end(err) {
this.res.end();
this.emit('end');
- if (this.domain) this.domain.dispose();
-
this.debug('ended the connection');
return this.ended = true;
});
@@ -772,6 +770,7 @@ Page.readable('configure', function configure(req, res) {
// Emit a page configuration event so plugins can hook in to this.
//
this.pipe.emit('page:configure', this);
+ res.once('close', this.emits('close'));
//
// If we have a `no_pagelet_js` flag, we should force a different
View
1  test/middleware.test.js
@@ -16,7 +16,6 @@ describe('middleware', function () {
app = new Pipe(server, {
pages: __dirname +'/fixtures/pages'
, dist: '/tmp/dist'
- , domains: true
});
server.portnumber = common.port;
View
1  test/page.test.js
@@ -19,7 +19,6 @@ describe('Page', function () {
app = new Pipe(server, {
pages: __dirname +'/fixtures/pages'
, dist: '/tmp/dist'
- , domains: true
});
page = new Page(app);
View
25 test/pipe.test.js
@@ -16,7 +16,6 @@ describe('Pipe', function () {
app = new Pipe(server, {
pages: __dirname +'/fixtures/pages'
, dist: '/tmp/dist'
- , domains: true
});
server.portnumber = common.port;
@@ -180,21 +179,25 @@ describe('Pipe', function () {
});
describe('#define', function () {
- it('adds the Page to the pages collection', function () {
+ it('adds the Page to the pages collection', function (next) {
var faq = require(__dirname + '/fixtures/pages/faq');
- app.define(faq);
+ app.define(faq, function (err) {
+ if (err) return next(err);
- expect(app.pages).to.have.length(6);
- expect(app.pages[2]).to.be.an('function');
- faq.prototype.dependencies = [];
+ expect(app.pages).to.have.length(6);
+ expect(app.pages[2]).to.be.an('function');
+ faq.prototype.dependencies = [];
+ });
});
- it('will resolve and add the page if directory or array', function () {
- app.define(__dirname + '/fixtures/pages');
+ it('will resolve and add the page if directory or array', function (next) {
+ app.define(__dirname + '/fixtures/pages', function (err) {
+ if (err) return next(err);
- expect(app.pages).to.have.length(8);
- app.pages.forEach(function (page) {
- expect(page).to.have.property('id');
+ expect(app.pages).to.have.length(8);
+ app.pages.forEach(function (page) {
+ expect(page).to.have.property('id');
+ });
});
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.