Comparing version 1.0.1 to 1.1.0
22
index.js
@@ -7,2 +7,4 @@ var EventEmitter = require('events').EventEmitter, | ||
compress = require('compression'), | ||
consolidate = require('consolidate'), | ||
cookieParser = require('cookie-parser'), | ||
errorHandler = require('errorhandler'), | ||
@@ -21,2 +23,6 @@ gracefulExit = require('express-graceful-exit'); | ||
options.errorHandler = typeof options.errorHandler !== 'undefined' ? options.errorHandler : Server.defaultOptions.errorHandler; | ||
options.parseCookies = typeof options.parseCookies !== 'undefined' ? options.parseCookies : Server.defaultOptions.parseCookies; | ||
options.viewDir = options.viewDir || Server.defaultOptions.viewDir; | ||
options.viewEngine = options.viewEngine || Server.defaultOptions.viewEngine; | ||
options.viewEngineSuffix = options.viewEngineSuffix || Server.defaultOptions.viewEngineSuffix; | ||
this.options = options; | ||
@@ -43,2 +49,9 @@ | ||
// Setup the views | ||
if (options.viewDir && options.viewEngine) { | ||
this.app.engine('html', consolidate[options.viewEngine]); | ||
this.app.set('view engine', options.viewEngineSuffix); | ||
this.app.set('views', options.viewDir); | ||
} | ||
// Setup middleware | ||
@@ -50,2 +63,5 @@ this.app.use(gracefulExit.middleware(this.app)); | ||
} | ||
if (options.parseCookies) { | ||
this.app.use(cookieParser()); | ||
} | ||
}; | ||
@@ -61,3 +77,7 @@ util.inherits(Server, EventEmitter); | ||
compress: true, | ||
errorHandler: true | ||
errorHandler: true, | ||
parseCookies: false, | ||
viewDir: null, | ||
viewEngine: null, | ||
viewEngineSuffix: 'html' | ||
}; | ||
@@ -64,0 +84,0 @@ |
{ | ||
"name": "app-server", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "An express server with logging, zero-downtime, and common-middleware", | ||
@@ -25,2 +25,4 @@ "main": "index.js", | ||
"compression": "^1.4.3", | ||
"consolidate": "^0.12.1", | ||
"cookie-parser": "^1.3.5", | ||
"errorhandler": "^1.3.5", | ||
@@ -27,0 +29,0 @@ "express": "^4.12.3", |
@@ -11,2 +11,4 @@ # App Server | ||
- [Logtastic](https://www.npmjs.com/package/logtastic) | ||
- [Consolidate](https://www.npmjs.com/package/consolidate) | ||
- [Cookie Parser](https://www.npmjs.com/package/cookie-parser) | ||
@@ -26,7 +28,20 @@ It setup sane defaults for these modules and exposes simple confiuration options for tweaking. But overall it is an opinionated method for setting up an express service. | ||
var server = new Server(); | ||
// All these options are set to their default values | ||
var server = new Server({ | ||
port: 3000, | ||
hostname: null, | ||
logDir: 'log', | ||
logger: logtastic, // An instance of Logtastic | ||
trustProxy: true, | ||
compress: true, | ||
errorHandler: true, | ||
parseCookies: false, | ||
viewDir: null, // Full path to views | ||
viewEngine: null, // One of the modules provied by consolidate | ||
viewEngineSuffix: 'html' | ||
}); | ||
// Setup routes | ||
server.app.post('/', function(req, res) { | ||
res.status(200).json({hello: 'world'}) | ||
res.status(200).json({hi: 'planet'}); | ||
}); | ||
@@ -33,0 +48,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6550
117
50
7
+ Addedconsolidate@^0.12.1
+ Addedcookie-parser@^1.3.5
+ Addedconsolidate@0.12.1(transitive)
+ Addedcookie@0.7.2(transitive)
+ Addedcookie-parser@1.4.7(transitive)