Repository navigation
Expand file tree
/
Copy pathapp.config.js
More file actions
60 lines (57 loc) · 2.78 KB
/
Copy pathapp.config.js
File metadata and controls
60 lines (57 loc) · 2.78 KB
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
/**
* Dynamic app config: app.json plus the values that differ per build.
*
* - `extra.pushGateway`: the push gateway this build registers its APNs/FCM tokens with
* (equinox cmd/pushgateway, run by whoever publishes the build - it holds the build's
* Apple key and Firebase credentials). Override with EXPO_PUBLIC_PUSH_GATEWAY, e.g.
* http://127.0.0.1:4020 in development (with `adb reverse tcp:4020 tcp:4020`).
* - `extra.fcm`: the Firebase project the Android build receives FCM pushes through, from
* STRAFE_FCM_PROJECT_ID / STRAFE_FCM_APP_ID / STRAFE_FCM_API_KEY / STRAFE_FCM_SENDER_ID.
* Left out, the build has no FCM and Android push uses UnifiedPush only. Ignored in a foss
* build, which has no Firebase to give it to.
* - `extra.distribution`: STRAFE_DISTRIBUTION, which Android build this is (default `play`):
* - `play`: Firebase Cloud Messaging (with `extra.fcm`) and UnifiedPush - Google Play and
* direct downloads;
* - `foss`: UnifiedPush only, with no Firebase or any other Google library in the app at all -
* F-Droid and the other stores that take free software only.
* plugins/withStrafePushAndroid.js builds the matching flavor of modules/strafe-push.
*
* Instances need none of this: they speak standard Web Push to whatever endpoint a device
* registered. See docs/PUSH.md in StrafeChat/deploy.
*
* - `extra.defaultInstance`: what the instance field offers on a fresh install (any other
* instance is a tap on the field away). STRAFE_DEFAULT_INSTANCE overrides it for a build of
* your own; set it to an empty string for no default.
*/
const DEFAULT_PUSH_GATEWAY = 'https://app.strafe.chat/push';
const DEFAULT_INSTANCE = 'app.strafe.chat';
const DISTRIBUTIONS = ['play', 'foss'];
function distribution() {
const value = (process.env.STRAFE_DISTRIBUTION || 'play').trim();
if (!DISTRIBUTIONS.includes(value)) {
throw new Error(`STRAFE_DISTRIBUTION must be one of ${DISTRIBUTIONS.join(', ')} (got "${value}")`);
}
return value;
}
function fcmConfig() {
const projectId = process.env.STRAFE_FCM_PROJECT_ID;
const applicationId = process.env.STRAFE_FCM_APP_ID;
const apiKey = process.env.STRAFE_FCM_API_KEY;
const senderId = process.env.STRAFE_FCM_SENDER_ID;
if (!projectId || !applicationId || !apiKey || !senderId) return undefined;
return { projectId, applicationId, apiKey, senderId };
}
module.exports = ({ config }) => {
const dist = distribution();
const fcm = dist === 'play' ? fcmConfig() : undefined;
return {
...config,
extra: {
...config.extra,
distribution: dist,
pushGateway: (process.env.EXPO_PUBLIC_PUSH_GATEWAY || DEFAULT_PUSH_GATEWAY).replace(/\/+$/, ''),
defaultInstance: (process.env.STRAFE_DEFAULT_INSTANCE ?? DEFAULT_INSTANCE).trim(),
...(fcm ? { fcm } : {}),
},
};
};