Always use http-agent for hooks and triggers (#4800)
This commit is contained in:
committed by
Florent Vilmart
parent
9bff44b446
commit
c5e8470e36
@@ -19,13 +19,11 @@ export class HooksController {
|
||||
_applicationId:string;
|
||||
_webhookKey:string;
|
||||
database: any;
|
||||
keepAlive: boolean;
|
||||
|
||||
constructor(applicationId:string, databaseController, webhookKey, keepAlive) {
|
||||
constructor(applicationId:string, databaseController, webhookKey) {
|
||||
this._applicationId = applicationId;
|
||||
this._webhookKey = webhookKey;
|
||||
this.database = databaseController;
|
||||
this.keepAlive = keepAlive;
|
||||
}
|
||||
|
||||
load() {
|
||||
@@ -93,7 +91,7 @@ export class HooksController {
|
||||
}
|
||||
|
||||
addHookToTriggers(hook) {
|
||||
var wrappedFunction = wrapToHTTPRequest(hook, this._webhookKey, this.keepAlive);
|
||||
var wrappedFunction = wrapToHTTPRequest(hook, this._webhookKey);
|
||||
wrappedFunction.url = hook.url;
|
||||
if (hook.className) {
|
||||
triggers.addTrigger(hook.triggerName, hook.className, wrappedFunction, this._applicationId)
|
||||
@@ -167,7 +165,7 @@ export class HooksController {
|
||||
}
|
||||
}
|
||||
|
||||
function wrapToHTTPRequest(hook, key, keepAlive) {
|
||||
function wrapToHTTPRequest(hook, key) {
|
||||
return (req, res) => {
|
||||
const jsonBody = {};
|
||||
for (var i in req) {
|
||||
@@ -188,10 +186,8 @@ function wrapToHTTPRequest(hook, key, keepAlive) {
|
||||
body: JSON.stringify(jsonBody),
|
||||
};
|
||||
|
||||
if (keepAlive) {
|
||||
const agent = hook.url.startsWith('https') ? HTTPAgents['https'] : HTTPAgents['http'];
|
||||
jsonRequest.agent = agent;
|
||||
}
|
||||
|
||||
if (key) {
|
||||
jsonRequest.headers['X-Parse-Webhook-Key'] = key;
|
||||
|
||||
@@ -150,9 +150,8 @@ export function getHooksController(options: ParseServerOptions, databaseControll
|
||||
const {
|
||||
appId,
|
||||
webhookKey,
|
||||
hookKeepAlive,
|
||||
} = options;
|
||||
return new HooksController(appId, databaseController, webhookKey, hookKeepAlive);
|
||||
return new HooksController(appId, databaseController, webhookKey);
|
||||
}
|
||||
|
||||
interface PushControlling {
|
||||
|
||||
@@ -302,11 +302,6 @@ module.exports.ParseServerOptions = {
|
||||
"env": "PARSE_SERVER_LIVE_QUERY_SERVER_OPTIONS",
|
||||
"help": "Live query server configuration options (will start the liveQuery server)",
|
||||
"action": parsers.objectParser
|
||||
},
|
||||
"hookKeepAlive": {
|
||||
"env": "PARSE_SERVER_HOOK_KEEP_ALIVE",
|
||||
"help": "Keep hook HTTP connections alive",
|
||||
"action": parsers.booleanParser
|
||||
}
|
||||
};
|
||||
module.exports.CustomPagesOptions = {
|
||||
|
||||
@@ -131,8 +131,6 @@ export interface ParseServerOptions {
|
||||
startLiveQueryServer: ?boolean;
|
||||
/* Live query server configuration options (will start the liveQuery server) */
|
||||
liveQueryServerOptions: ?LiveQueryServerOptions;
|
||||
/* Keep hook HTTP connections alive */
|
||||
hookKeepAlive: ?boolean;
|
||||
|
||||
__indexBuildCompletionCallbackForTests: ?()=>void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user