Last active
December 16, 2015 09:59
-
-
Save timshadel/5416837 to your computer and use it in GitHub Desktop.
Middleware stack config ideas.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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