-
Notifications
You must be signed in to change notification settings - Fork 0
/
universal-links.js
51 lines (44 loc) · 1.54 KB
/
universal-links.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
import { getSettings } from 'meteor/quave:settings';
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
const PACKAGE_NAME = 'quave:universal-links';
const settings = getSettings({ packageName: PACKAGE_NAME });
export const APPLE_APP_SITE_ASSOCIATION_PATH = '/apple-app-site-association';
export const respondAppleAppSiteAssociation = (req, res, customSettings) => {
const { appleTeamId, appleBundleId, paths } =
customSettings && customSettings.appleTeamId ? customSettings : settings;
if (!appleTeamId || !appleBundleId) {
res.setHeader('Content-Type', 'text/html');
res.writeHead(405);
res.end(
`<h1>${PACKAGE_NAME} Native App not configured for iOS, add to your settings.packages.[quave:universal-links] the following keys: appleTeamId and appleBundleId</h1>`
);
return;
}
const appSiteAssociation = {
applinks: {
apps: [],
details: [
{
appID: `${appleTeamId}.${appleBundleId}`,
paths: paths || ['*'],
},
],
},
};
res.setHeader('Content-Type', 'application/json');
res.writeHead(200);
res.end(JSON.stringify(appSiteAssociation));
};
export const createResponderAppleAppSiteAssociation = customSettings => (
req,
res
) => respondAppleAppSiteAssociation(req, res, customSettings);
export const registerUniversalLinksHandler = customSettings => {
WebApp.connectHandlers.use(
APPLE_APP_SITE_ASSOCIATION_PATH,
Meteor.bindEnvironment((req, res) =>
respondAppleAppSiteAssociation(req, res, customSettings)
)
);
};