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:
committed by
Natan Rolnik
parent
73260897cd
commit
41358d2226
@@ -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.
|
* `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.
|
* `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`.
|
* `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
|
##### Logging
|
||||||
|
|
||||||
|
|||||||
@@ -249,4 +249,7 @@ export default {
|
|||||||
help: "Live query server configuration options (will start the liveQuery server)",
|
help: "Live query server configuration options (will start the liveQuery server)",
|
||||||
action: objectParser
|
action: objectParser
|
||||||
},
|
},
|
||||||
|
"middleware": {
|
||||||
|
help: "middleware for express server, can be string or function"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import definitions from './definitions/parse-server';
|
|||||||
import cluster from 'cluster';
|
import cluster from 'cluster';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import runner from './utils/runner';
|
import runner from './utils/runner';
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
const help = function(){
|
const help = function(){
|
||||||
console.log(' Get Started guide:');
|
console.log(' Get Started guide:');
|
||||||
@@ -30,9 +31,20 @@ const help = function(){
|
|||||||
|
|
||||||
function startServer(options, callback) {
|
function startServer(options, callback) {
|
||||||
const app = express();
|
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 api = new ParseServer(options);
|
||||||
const sockets = {};
|
const sockets = {};
|
||||||
|
|
||||||
app.use(options.mountPath, api);
|
app.use(options.mountPath, api);
|
||||||
|
|
||||||
const server = app.listen(options.port, options.host, callback);
|
const server = app.listen(options.port, options.host, callback);
|
||||||
|
|||||||
Reference in New Issue
Block a user