-
Notifications
You must be signed in to change notification settings - Fork 27
/
config.js
67 lines (64 loc) · 1.81 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
66
67
// These URL paths will be transformed to CN mirrors.
var mirrors = {
"//developers.google.com" : "developers.google.cn",
"//firebase.google.com" : "firebase.google.cn",
"//developer.android.com" : "developer.android.google.cn",
"//source.android.com" : "source.android.google.cn",
"//www.tensorflow.org" : "tensorflow.google.cn",
"//tfhub.dev" : "hub.tensorflow.google.cn",
"//angular.io" : "angular.cn",
"//translate.google.com" : "translate.google.cn",
"//careers.google.com" : "careers.google.cn",
"//go.dev" : "golang.google.cn",
"//golang.org" : "golang.google.cn",
"//sum.golang.org" : "sum.golang.google.cn"
};
// These URL paths are not available on CN mirrors, therefore won't be transformed.
var skiplist = [
"//careers.google.com/jobs"
];
function redirectRules() {
let res = [];
let id = 1;
for (const url of skiplist) {
res.push({
"id": id++,
"action": {
"type": "allow"
},
"condition": {
"urlFilter": url,
"excludedResourceTypes": ["other"],
"isUrlFilterCaseSensitive": false
}
});
}
for (const key in mirrors) {
res.push({
"id": id++,
"action": {
"type": "redirect",
"redirect": {
"transform": {
"host": mirrors[key]
}
}
},
"condition": {
"urlFilter": key,
"excludedResourceTypes": ["other"],
"isUrlFilterCaseSensitive": false
}
});
}
return res;
}
// Export rules to 'rules.json' (node.js is required)
const fs = require('fs');
fs.writeFile('rules.json', JSON.stringify(redirectRules()), err => {
if (err) {
console.error(err);
} else {
console.log('rules.json created.');
}
});