-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve filter #76
Improve filter #76
Changes from all commits
b13e5bc
eff6506
8a7b731
4950816
f63adaf
2efae6d
b3e923e
3048c1e
5823c4d
ac318a3
d29c81c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ interface FinalizedBlock { | |
} | ||
|
||
export interface ApiStatus { | ||
restGatewayUrl: string; | ||
isAvailable: boolean; | ||
isHttpsEnabled?: boolean; | ||
nodeStatus?: NodeStatus; | ||
|
@@ -66,10 +67,10 @@ export class ApiNodeService { | |
static getStatus = async (host: string): Promise<ApiStatus> => { | ||
try { | ||
const isHttps = await ApiNodeService.isHttpsEnabled(host); | ||
const protocol = isHttps ? 'https' : 'http'; | ||
const protocol = isHttps ? 'https:' : 'http:'; | ||
const port = isHttps ? 3001 : 3000; | ||
|
||
logger.info(`Getting node status for: ${protocol}://${host}:${port}`); | ||
logger.info(`Getting node status for: ${protocol}//${host}:${port}`); | ||
|
||
const [nodeInfo, chainInfo, nodeServer, nodeHealth] = await Promise.all([ | ||
ApiNodeService.getNodeInfo(host, port, protocol), | ||
|
@@ -79,6 +80,7 @@ export class ApiNodeService { | |
]); | ||
|
||
let apiStatus = { | ||
restGatewayUrl: `${protocol}//${host}:${port}`, | ||
isAvailable: true, | ||
lastStatusCheck: Date.now(), | ||
}; | ||
|
@@ -118,6 +120,7 @@ export class ApiNodeService { | |
} catch (e) { | ||
logger.error(`Fail to request host node status: ${host}`, e); | ||
return { | ||
restGatewayUrl: `http://${host}:3000`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this default value. It could happen that the rest url is on 3001 https but rest fails to get the current status. This method may swap from 3001 to 3000 when 3000 might not be there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if the node is not healthy or unreached, it nodes filter won't return it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the catch is caught, why still return the json? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just a record need to be stored in the database. |
||
isAvailable: false, | ||
lastStatusCheck: Date.now(), | ||
}; | ||
|
@@ -126,7 +129,7 @@ export class ApiNodeService { | |
|
||
static getNodeInfo = async (host: string, port: number, protocol: string): Promise<NodeInfo | null> => { | ||
try { | ||
return (await HTTP.get(`${protocol}://${host}:${port}/node/info`)).data; | ||
return (await HTTP.get(`${protocol}//${host}:${port}/node/info`)).data; | ||
} catch (e) { | ||
logger.error(`Fail to request /node/info: ${host}`, e); | ||
return null; | ||
|
@@ -135,7 +138,7 @@ export class ApiNodeService { | |
|
||
static getNodeChainInfo = async (host: string, port: number, protocol: string): Promise<ChainInfo | null> => { | ||
try { | ||
return (await HTTP.get(`${protocol}://${host}:${port}/chain/info`)).data; | ||
return (await HTTP.get(`${protocol}//${host}:${port}/chain/info`)).data; | ||
} catch (e) { | ||
logger.error(`Fail to request /chain/info: ${host}`, e); | ||
return null; | ||
|
@@ -144,7 +147,7 @@ export class ApiNodeService { | |
|
||
static getNodeServer = async (host: string, port: number, protocol: string): Promise<ServerInfo | null> => { | ||
try { | ||
const nodeServerInfo = (await HTTP.get(`${protocol}://${host}:${port}/node/server`)).data; | ||
const nodeServerInfo = (await HTTP.get(`${protocol}//${host}:${port}/node/server`)).data; | ||
|
||
return nodeServerInfo.serverInfo; | ||
} catch (e) { | ||
|
@@ -155,7 +158,7 @@ export class ApiNodeService { | |
|
||
static getNodeHealth = async (host: string, port: number, protocol: string): Promise<NodeStatus | null> => { | ||
try { | ||
const health = (await HTTP.get(`${protocol}://${host}:${port}/node/health`)).data; | ||
const health = (await HTTP.get(`${protocol}//${host}:${port}/node/health`)).data; | ||
|
||
return health.status; | ||
} catch (e) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the ssl is undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the list will return http and https together