That looks like a pretty cool / appropriately abstracted series of events for a typical server lifecycle. I would say though that typically `start()` would take a callback, and I don't think I've ever seen an event handler take a callback like that either since the EE paradigm is implied decoupling.
Cheers, Adam Crabtree On Mon, Mar 4, 2013 at 1:36 PM, Gagle <[email protected]> wrote: > Hi, > > I'd like to share with you a module that I've made trying to implements > the base of a robust web server that never breaks and can shutdown > gracefully even using workers. These 2 reasons were my primary goal. > > The module is: grace <https://github.com/Gagle/Node-Grace> > > The base of any web server: > > var express = require ("express"); > var grace = require ("../lib/grace"); > > var app = grace.create (); > > //Default error handler > app.on ("error", function (error){ > console.error (error); > }); > > app.on ("start", function (){ > var ex = express (); > > //Request error handler, this should be the first middleware > ex.use (app.errorHandler (function (error, req, res, preventDefault){ > //Here you'll typically send to the user a 500 error > res.send (500); > })); > > //Middleware > ex.use (function (req, res, next){ > res.send (200); > }); > > //Express error handler, this should be the last middleware > ex.use (app.redirectError ()); > > ex.listen (1337, "localhost"); > }); > > app.on ("shutdown", function (cb){ > //Clean up > console.log ("shutting down"); > cb (); > }); > > app.on ("exit", function (code){ > console.log ("bye (" + code + ")"); > }); > > app.timeout (1000, function (){ > console.error ("timed out, forcing shutdown"); > }); > > app.start (); > > > I'm using it (with workers) on a distributed web app with big data. What > do you think? Excellent, good, bad or terrible? > > -- > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Better a little with righteousness than much gain with injustice. Proverbs 16:8 -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
