Skip to content

Instantly share code, notes, and snippets.

@timshadel
Last active December 16, 2015 09:59
Show Gist options
  • Save timshadel/5416837 to your computer and use it in GitHub Desktop.
Save timshadel/5416837 to your computer and use it in GitHub Desktop.
Middleware stack config ideas.
/**
* Module dependencies.
*/
var stack = require("simple-stack-common")
, cors = require("connect-xcors");
/**
* Expose the stack
*/
module.exports = exports = function(config) {
if (!config) config = {};
// Create a simple-stack-common app
var pack = stack(config);
pack
.useAfter("base", cors)
.use(require("./lib/not-found"))
.use(require("./lib/error-handler")); // the change is pack-n-stack would auto-apply config.errorHandler
// Return the pack
return pack;
};
/**
* Expose connect.middleware as stack.*
*/
stack.middleware(exports);
/**
* Module dependencies.
*/
var stack = require('./api-stack');
/**
* Configure the api stack
*/
var config = {
errorHandler: {
message: ["<pre>", "</pre>"]
}
};
/**
* Expose the app
*/
var app = module.exports = stack(config);
/**
* Module dependencies.
*/
var stack = require("simple-stack-common")
, cors = require("connect-xcors")
, notFound = require("./lib/not-found")
, errorHandler = require("./lib/error-handler");
/**
* Expose the stack
*/
module.exports = exports = function(config) {
if (!config) config = {};
function configure(fn) {
return fn(config[fn.name]);
}
// Create a simple-stack-common app
var pack = stack(config);
pack
.useAfter("base", configure(cors) )
.use( configure(notFound) )
.use( configure(errorHandler) ); // the change is pack-n-stack would auto-apply config.errorHandler
// Return the pack
return pack;
};
/**
* Expose connect.middleware as stack.*
*/
stack.middleware(exports);
/**
* Module dependencies.
*/
var stack = require("simple-stack-common")
, cors = require("connect-xcors")
, notFound = require("./lib/not-found")
, errorHandler = require("./lib/error-handler");
/**
* Expose the stack
*/
module.exports = exports = function(config) {
if (!config) config = {};
// Create a simple-stack-common app
var pack = stack(config);
pack
.useAfter("base", pack.configure(cors) )
.use( pack.configure(notFound) )
.use( pack.configure(errorHandler) ); // the change is pack-n-stack would auto-apply config.errorHandler
// Return the pack
return pack;
};
/**
* Expose connect.middleware as stack.*
*/
stack.middleware(exports);
/**
* Module dependencies.
*/
var stack = require("simple-stack-common")
, cors = require("connect-xcors")
, notFound = require("./lib/not-found")
, errorHandler = require("./lib/error-handler");
/**
* Expose the stack
*/
module.exports = exports = function(config) {
if (!config) config = {};
// Create a simple-stack-common app
var pack = stack(config);
pack
.useAfter("base", cors(config[cors.name]) )
.use( notFound(config[notFound.name]) )
.use( errorHandler(config[errorHandler.name]) ); // the change is pack-n-stack would auto-apply config.errorHandler
// Return the pack
return pack;
};
/**
* Expose connect.middleware as stack.*
*/
stack.middleware(exports);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment