Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
cdn-node-checker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
cdn-node-checker
Commits
9109bce0
Commit
9109bce0
authored
Mar 02, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
befacbb3
Pipeline
#10228
failed with stages
in 56 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
31 deletions
+58
-31
run.ts
run.ts
+58
-31
No files found.
run.ts
View file @
9109bce0
...
...
@@ -85,49 +85,69 @@ class Checker {
private
checkMethods
=
new
Map
<
string
,
(
record
:
RecordRule
,
address
:
string
)
=>
Promise
<
ConnectResult
>
>
();
>
();
private
availableRecordRules
:
RecordRule
[];
private
async
filterRecordRules
()
{
this
.
availableRecordRules
=
[];
await
Promise
.
all
(
this
.
config
.
cdnRecords
.
map
(
async
(
rule
)
=>
{
if
(
rule
.
protocol
===
'
tcp
'
&&
rule
.
source
)
{
this
.
message
(
`Checking source
${
rule
.
source
}
:
${
rule
.
port
}
.`
);
try
{
const
ms
=
await
this
.
checkTcpProcess
(
rule
.
source
,
rule
.
port
)
this
.
availableRecordRules
.
push
(
rule
);
this
.
message
(
`Source
${
rule
.
source
}
:
${
rule
.
port
}
is good:
${
ms
}
ms.`
)
}
catch
(
e
)
{
this
.
message
(
`Skipping rule
${
rule
.
match
}
fo source
${
rule
.
source
}
:
${
rule
.
port
}
r unhealthy:
${
e
.
toString
()}
`
)
}
}
else
if
(
rule
.
source
&&
(
rule
.
protocol
===
'
http
'
||
rule
.
protocol
===
'
https
'
))
{
const
availableTestDomains
:
string
[]
=
[];
for
(
const
domain
of
rule
.
testDomains
)
{
this
.
message
(
`Checking source domain
${
domain
}
:
${
rule
.
port
}
.`
);
const
errMessage
=
await
this
.
tryConnectHttp
(
rule
.
protocol
,
domain
,
rule
.
port
,
domain
);
if
(
errMessage
)
{
this
.
message
(
`Skipping domain
${
domain
}
of rule
${
rule
.
match
}
for bad source:
${
errMessage
}
`
);
await
Promise
.
all
(
this
.
config
.
cdnRecords
.
map
(
async
(
rule
)
=>
{
if
(
rule
.
protocol
===
'
tcp
'
&&
rule
.
source
)
{
this
.
message
(
`Checking source
${
rule
.
source
}
:
${
rule
.
port
}
.`
);
try
{
const
ms
=
await
this
.
checkTcpProcess
(
rule
.
source
,
rule
.
port
);
this
.
availableRecordRules
.
push
(
rule
);
this
.
message
(
`Source
${
rule
.
source
}
:
${
rule
.
port
}
is good:
${
ms
}
ms.`
,
);
}
catch
(
e
)
{
this
.
message
(
`Skipping rule
${
rule
.
match
}
fo source
${
rule
.
source
}
:
${
rule
.
port
}
unhealthy:
${
e
.
toString
()}
`
,
);
}
}
else
if
(
rule
.
source
&&
(
rule
.
protocol
===
'
http
'
||
rule
.
protocol
===
'
https
'
)
)
{
const
availableTestDomains
:
string
[]
=
[];
for
(
const
domain
of
rule
.
testDomains
)
{
this
.
message
(
`Checking source domain
${
domain
}
:
${
rule
.
port
}
.`
);
const
errMessage
=
await
this
.
tryConnectHttp
(
rule
.
protocol
,
domain
,
rule
.
port
,
domain
,
);
if
(
errMessage
)
{
this
.
message
(
`Skipping domain
${
domain
}
of rule
${
rule
.
match
}
for bad source:
${
errMessage
}
`
,
);
}
else
{
this
.
message
(
`Source domain
${
domain
}
is good.`
);
availableTestDomains
.
push
(
domain
);
}
}
if
(
availableTestDomains
.
length
)
{
rule
.
testDomains
=
availableTestDomains
;
this
.
availableRecordRules
.
push
(
rule
);
}
else
{
this
.
message
(
`Source domain
${
domain
}
is good.`
);
availableTestDomains
.
push
(
domain
);
this
.
message
(
`Skipping rule
${
rule
.
match
}
for no available sources.`
,
);
}
}
if
(
availableTestDomains
.
length
)
{
rule
.
testDomains
=
availableTestDomains
;
this
.
availableRecordRules
.
push
(
rule
);
}
else
{
this
.
message
(
`Skipping rule
${
rule
.
match
}
for no available sources.`
);
this
.
availableRecordRules
.
push
(
rule
);
}
}
else
{
this
.
availableRecordRules
.
push
(
rule
);
}
}))
}),
);
}
private
async
connectHttpProcess
(
url
:
string
,
hostHeader
:
string
)
{
try
{
await
axios
.
get
(
url
,
{
headers
:
{
Host
:
hostHeader
},
headers
:
{
Host
:
hostHeader
},
timeout
:
this
.
config
.
timeout
,
validateStatus
:
(
status
)
=>
status
<
500
,
});
...
...
@@ -311,6 +331,13 @@ class Checker {
const
matchCDNRecord
=
this
.
availableRecordRules
.
find
((
r
)
=>
record
.
RR
.
match
(
r
.
match
),
);
if
(
!
matchCDNRecord
)
{
// source down
this
.
message
(
`Will skip record
${
record
.
RR
}
.
${
this
.
config
.
domain
}
=>
${
record
.
Value
}
because source is down.`
,
);
continue
;
}
const
{
port
,
protocol
}
=
matchCDNRecord
;
const
isCDN
=
this
.
isCDNRecord
(
record
);
const
recordInfo
:
DomainRecordInfo
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment