Skip to content

Commit f173336

Browse files
committed
generall support github
1 parent ce9f4dc commit f173336

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const PREFLIGHT_INIT = {
3636
*/
3737
function makeRes(body, status = 200, headers = {}) {
3838
headers['access-control-allow-origin'] = '*'
39-
return new Response(body, {status, headers})
39+
return new Response(body, { status, headers })
4040
}
4141

4242

@@ -77,13 +77,14 @@ async function fetchHandler(e) {
7777
const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-).*$/i
7878
const exp4 = /^(?:https?:\/\/)?raw\.githubusercontent\.com\/.+?\/.+?\/.+?\/.+$/i
7979
const exp5 = /^(?:https?:\/\/)?gist\.(?:githubusercontent|github)\.com\/.+?\/.+?\/.+$/i
80+
const exp6 = /^(?:https?:\/\/).+?\.github\.com\/+$/i
8081
if (path.search(exp1) === 0 || path.search(exp5) === 0 || !Config.cnpmjs && (path.search(exp3) === 0 || path.search(exp4) === 0)) {
8182
return httpHandler(req, path)
8283
} else if (path.search(exp2) === 0) {
83-
if (Config.jsdelivr){
84+
if (Config.jsdelivr) {
8485
const newUrl = path.replace('/blob/', '@').replace(/^(?:https?:\/\/)?github\.com/, 'https://cdn.jsdelivr.net/gh')
8586
return Response.redirect(newUrl, 302)
86-
}else{
87+
} else {
8788
path = path.replace('/blob/', '/raw/')
8889
return httpHandler(req, path)
8990
}
@@ -93,7 +94,10 @@ async function fetchHandler(e) {
9394
} else if (path.search(exp4) === 0) {
9495
const newUrl = path.replace(/(?<=com\/.+?\/.+?)\/(.+?\/)/, '@$1').replace(/^(?:https?:\/\/)?raw\.githubusercontent\.com/, 'https://cdn.jsdelivr.net/gh')
9596
return Response.redirect(newUrl, 302)
96-
} else {
97+
} else if (path.search(exp6) === 0) {
98+
return httpHandler(req, path)
99+
}
100+
else {
97101
return fetch(ASSET_URL + path)
98102
}
99103
}

0 commit comments

Comments
 (0)