FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
docsify/middleware.js at develop · docsifyjs/docsify · GitHub
docsifyjs
/
docsify
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
5.8k
Star
31.5k
Code
Issues
62
Pull requests
29
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
docsify
/
middleware.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (50 loc) · 1.66 KB
Breadcrumbs
docsify
/
middleware.js
Copy path
File metadata and controls
53 lines (50 loc) · 1.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// Exports
// =============================================================================
export
const
config
=
{
matcher
:
[
'/preview/(index.html)?'
]
,
}
;
// Rewrite rules shared with local server configurations
export
const
rewriteRules
=
[
// Replace CDN URLs with local paths
{
match
:
/
h
t
t
p
s
?
.
*
\/
C
H
A
N
G
E
L
O
G
.
m
d
/
g
,
replace
:
'/CHANGELOG.md'
,
}
,
{
// CDN versioned default
// Ex1: //cdn.com/package-name
// Ex2: http://cdn.com/package-name@1.0.0
// Ex3: https://cdn.com/package-name@latest
match
:
/
(?:
h
t
t
p
s
?
:
)
*
\/
\/
.
*
c
d
n
.
*
d
o
c
s
i
f
y
[
@
\d
.
l
a
t
e
s
t
]
*
(?
=
[
"
'
]
)
/
g
,
replace
:
'/dist/docsify.min.js'
,
}
,
{
// CDN paths to local paths
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js
// Ex2: http://cdn.com/package-name@1.0.0/dist/file.js => /dist/file.js
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js
match
:
/
(?:
h
t
t
p
s
?
:
)
*
\/
\/
.
*
c
d
n
.
*
d
o
c
s
i
f
y
[
@
\d
.
l
a
t
e
s
t
]
*
\/
(?:
d
i
s
t
\/
)
/
g
,
replace
:
'/dist/'
,
}
,
]
;
// Serve virtual /preview/index.html
// Note: See vercel.json for preview routing configuration
// 1. Fetch index.html from /docs/ directory
// 2. Replace CDN URLs with local paths (see rewriteRules)
// 3. Return preview HTML
export
default
async
function
middleware
(
request
)
{
const
{
origin
}
=
new
URL
(
request
.
url
)
;
const
indexURL
=
`
${
origin
}
/docs/index.html`
;
const
indexHTML
=
await
fetch
(
indexURL
)
.
then
(
res
=>
res
.
text
(
)
)
;
const
previewHTML
=
rewriteRules
.
reduce
(
(
html
,
rule
)
=>
html
.
replace
(
rule
.
match
,
rule
.
replace
)
,
indexHTML
,
)
;
return
new
Response
(
previewHTML
,
{
status
:
200
,
headers
:
{
'content-type'
:
'text/html'
,
'x-robots-tag'
:
'noindex'
,
}
,
}
)
;
}
Back
|
FazBrowse Home
|
New Git URL