-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontroller.js
More file actions
61 lines (52 loc) · 2.14 KB
/
controller.js
File metadata and controls
61 lines (52 loc) · 2.14 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
61
var validator = require('./validator')
var parser = require('./parser')
function getResult(domain, bundleIdentifier, teamIdentifier) {
var respObj = { domains: {} };
var cleanedDomain = domain.replace(/https?:\/\//, '');
cleanedDomain = cleanedDomain.replace(/\/.*/, '');
var fileUrl = 'https://' + cleanedDomain + '/apple-app-site-association';
return validator.validate(fileUrl, bundleIdentifier, teamIdentifier)
.then(function (results) {
respObj.domains[domain] = results;
return respObj;
})
.catch(function (errorObj) {
//check if AASA file exists in the root domain
var noFile = false;
try {
fs.accessSync(fileUrl);
} catch (e) {
console.log('file does not exist in the root. checking .well-known')
noFile = true;
}
if (errorObj.serverError || errorObj.errorOutOfScope || errorObj.badDns || errorObj.httpsFailure || noFile) {
fileUrl = 'https://' + cleanedDomain + '/.well-known/apple-app-site-association';
return validator.validate(fileUrl, bundleIdentifier, teamIdentifier)
.then(function (results) {
respObj.domains[domain] = results;
return respObj;
}).catch(function (errorObj) {
respObj.domains[domain] = { errors: errorObj };
return respObj;
})
}
respObj.domains[domain] = { errors: errorObj };
return respObj;
});
}
function validateAASAFileFromDomain(domain, bundleIdentifier, teamIdentifier) {
return getResult(domain, bundleIdentifier, teamIdentifier)
.then(function (success) {
var parseResult = parser.parse(Object.keys(success.domains)[0], success);
return parseResult;
}).catch(function (err) {
return err;
})
}
function main() {
validateAASAFileFromDomain('facebook.com', '', '')
.then(function (result) {
console.log(result);
})
}
main()