express-loadmill
Advanced tools
Comparing version 0.0.6 to 0.1.0-beta
@@ -10,2 +10,5 @@ export = Loadmill; | ||
/** | ||
* Loadmill express middleware configuration options. | ||
*/ | ||
type LoadmillOptions = { | ||
@@ -15,3 +18,3 @@ /** | ||
*/ | ||
verifyToken?: string; | ||
verifyToken?: string | ||
@@ -21,3 +24,41 @@ /** | ||
*/ | ||
enableCors?: boolean; | ||
enableCors?: boolean | ||
/** | ||
* Optional monitoring configuration. | ||
* Sends data only during testing. | ||
*/ | ||
monitor?: { | ||
/** | ||
* Personal access token for Loadmill monitoring API. | ||
*/ | ||
apiToken: string | ||
/** | ||
* Enable monitoring during testing. | ||
* Default: true. | ||
*/ | ||
enabled?: boolean | ||
/** | ||
* The node process's associated (case insensitive) environment name (e.g. `Staging`, `Test`, `My_MacBook`, etc.). | ||
* In general, Loadmill will monitor a single environment per load test. | ||
* | ||
* May contain (only) alphanumeric characters, `-` and `_`. | ||
* Default: `default_env`. | ||
*/ | ||
envName?: string; | ||
/** | ||
* The node process's associated (case insensitive) app / component / micro-service name | ||
* (e.g. `web_app`, `billing_service`, `scheduler`, etc.). | ||
* | ||
* The app name is used to group together processes of the same "kind" and | ||
* aggregate their performance metrics. | ||
* | ||
* May contain (only) alphanumeric characters, `-` and `_`. | ||
* Default: `default_app`. | ||
*/ | ||
appName?: string; | ||
} | ||
}; |
31
index.js
module.exports = function (options) { | ||
var token = options && options.verifyToken; | ||
var verifyToken = options && options.verifyToken; | ||
var enableCookies = options && options.enableCookies; | ||
var enableCors = !options || options.enableCors == null || options.enableCors; | ||
if (options && options.monitor) { | ||
activateMonitoring(options.monitor); | ||
} | ||
return function (req, res, next) { | ||
checkCors({enableCors: enableCors, enableCookies: enableCookies}, req, res, function () { | ||
return verifyDomain(token, req, res, next); | ||
return verifyDomain(verifyToken, req, res, next); | ||
}); | ||
@@ -14,2 +18,19 @@ }; | ||
function activateMonitoring(monitorOptions) { | ||
if (monitorOptions.enabled == null || monitorOptions.enabled) { | ||
var loadmillMonitor; | ||
try { | ||
loadmillMonitor = require('loadmill-monitor'); | ||
} | ||
catch (err) { | ||
console.error("Failed to require optional dependency 'loadmill-monitor' - " + | ||
"did you remember to add it as a dependency to your package.json file?"); | ||
throw err; | ||
} | ||
loadmillMonitor(monitorOptions); | ||
} | ||
} | ||
function checkCors(corsOptions, req, res, next) { | ||
@@ -56,5 +77,5 @@ if (corsOptions.enableCors) { | ||
function verifyDomain(token, req, res, next) { | ||
if (token && req.url.indexOf("/loadmill-challenge/" + token + ".txt") === 0) { | ||
res.send(token); | ||
function verifyDomain(verifyToken, req, res, next) { | ||
if (verifyToken && req.url.indexOf("/loadmill-challenge/" + verifyToken + ".txt") === 0) { | ||
res.send(verifyToken); | ||
} | ||
@@ -61,0 +82,0 @@ else { |
{ | ||
"name": "express-loadmill", | ||
"version": "0.0.6", | ||
"version": "0.1.0-beta", | ||
"description": "Express middleware to enable crowdsourced load simulations via loadmill.com", | ||
@@ -17,3 +17,6 @@ "keywords": [ | ||
"author": "itaysabato <itay@loadmill.com>", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"optionalDependencies": { | ||
"loadmill-monitor": "^1.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
Mixed license
License(Experimental) Package contains multiple licenses.
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
18030
122
1
1