Adds ability to pass a middleware to CLI for instrumentation (#3554)

* Adds ability to pass a middleware to CLI for instrumentation

* Adds readme
This commit is contained in:
Florent Vilmart
2017-02-22 16:42:21 -05:00
committed by Natan Rolnik
parent 73260897cd
commit 41358d2226
3 changed files with 17 additions and 1 deletions

View File

@@ -217,6 +217,7 @@ The client keys used with Parse are no longer necessary with Parse Server. If yo
* `accountLockout` - Lock account when a malicious user is attempting to determine an account password by trial and error.
* `passwordPolicy` - Optional password policy rules to enforce.
* `customPages` - A hash with urls to override email verification links, password reset links and specify frame url for masking user-facing pages. Available keys: `parseFrameURL`, `invalidLink`, `choosePassword`, `passwordResetSuccess`, `verifyEmailSuccess`.
* `middleware` - (CLI only), a module name, function that is an express middleware. When using the CLI, the express app will load it just **before** mounting parse-server on the mount path. This option is useful for injecting a monitoring middleware.
##### Logging

View File

@@ -249,4 +249,7 @@ export default {
help: "Live query server configuration options (will start the liveQuery server)",
action: objectParser
},
"middleware": {
help: "middleware for express server, can be string or function"
}
};

View File

@@ -5,6 +5,7 @@ import definitions from './definitions/parse-server';
import cluster from 'cluster';
import os from 'os';
import runner from './utils/runner';
const path = require("path");
const help = function(){
console.log(' Get Started guide:');
@@ -30,9 +31,20 @@ const help = function(){
function startServer(options, callback) {
const app = express();
if (options.middleware) {
let middleware;
if (typeof options.middleware == 'function') {
middleware = options.middleware;
} if (typeof options.middleware == 'string') {
middleware = require(path.resolve(process.cwd(), options.middleware));
} else {
throw "middleware should be a string or a function";
}
app.use(middleware);
}
const api = new ParseServer(options);
const sockets = {};
app.use(options.mountPath, api);
const server = app.listen(options.port, options.host, callback);