-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
config.js
65 lines (56 loc) · 1.64 KB
/
config.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const functions = require('firebase-functions')
/**
* Get config from firebase config
* config().pricetrack.<KEY>
*
* @param key {string} Key to get
* @param default_val {object}
* @return {object}
*/
const getConfig = (key, default_val=false) => {
const configSet = functions.config().pricetrack || {}
return configSet[key] || default_val
}
/**
* Get sort key from req.params
* @param {[type]} key [description]
* @return {[type]} [description]
*/
const getSortKey = key => {
const defaultKey = 'created_at'
const validKeys = ['created_at', 'last_pull_at', 'created_at',
'last_update_at', 'price_change', 'price_change_at']
if (!key || validKeys.indexOf(key) == -1) return defaultKey
return key
}
// TODO: Get PROJECT_ID from env
const PROJECT_ID = 'duyet-price-tracker'
const IS_PROD = process.env.FUNCTION_TARGET ? true : false
console.log(`IS_PROD: ${IS_PROD} `
+ `FUNCTION_TARGET="${process.env.FUNCTION_TARGET}" `
+ `K_SERVICE="${process.env.K_SERVICE}"`)
/**
* Firebase functions url
* @type {[type]}
*/
const functionsUrl = !IS_PROD
? `http://localhost:5001/duyet-price-tracker/us-central1`
: `https://us-central1-${PROJECT_ID}.cloudfunctions.net`
const functionsUrlAsia = !IS_PROD
? `http://localhost:5001/duyet-price-tracker/us-central1`
: `https://asia-northeast1-${PROJECT_ID}.cloudfunctions.net`
/**
* Hosting root url
* @type {[type]}
*/
const hostingUrl = !IS_PROD
? `http://localhost:8000`
: getConfig('hosting_url', 'https://tracker.duyet.net')
module.exports = {
getConfig,
getSortKey,
functionsUrl,
functionsUrlAsia,
hostingUrl,
IS_PROD
}