-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
36 lines (32 loc) · 923 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Given the invocation arguments, detemines which platform we are on
* @param {any} first First arguemnt
* @param {any} second Second argument
* @param {...any} rest Rest arguments
*/
function getExecutingPlatform(first, second, ...rest) {
// get platform
// on amazon, second param is 'context' and hsa these fields
if (
second &&
typeof second.invokedFunctionArn === 'string'
&& typeof second.functionName === 'string'
&& typeof second.awsRequestId === 'string'
) {
return 'amazon'
}
if (
first &&
typeof first.method === 'string'
&& first.get // some methods that Express' Request objs alwys have
&& first.accepts
&& first.acceptsCharsets
&& first.param
) {
return 'google'
}
throw new Error("Couldn't recognize platform running this code, seems neither to be GC Functions nor Amazon Lambda");
}
module.exports = {
getExecutingPlatform
}