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