Make modules/classes work like middleware (for express and restify)