forked from Be-FaaS/BeFaaS-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
34 lines (32 loc) · 804 Bytes
/
helper.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
const fs = require('fs')
const path = require('path')
const helper = {
isLambda: !!process.env.AWS_LAMBDA_FUNCTION_NAME,
isGoogle: !!process.env.K_SERVICE && !!process.env.K_REVISION,
isAzure: !!process.env.IS_AZURE_FUNCTION_APP,
isTinyfaas: !!process.env.TINYFAAS,
isOpenfaas: !!process.env.IS_OPENFAAS,
isOpenwhisk: !!process.env.IS_OPENWHISK
}
module.exports = {
prefix: () => {
if (helper.isLambda) return '/:fn'
if (helper.isAzure) return '/api/:fn'
return null
},
generateRandomID: () => {
return Math.random()
.toString(36)
.slice(2, 10)
},
loadExperiment: () => {
try {
return JSON.parse(
fs.readFileSync(path.join(process.cwd(), 'experiment.json'), 'UTF-8')
)
} catch (e) {
return {}
}
},
...helper
}