-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created validator for Backend and Dmob API
- Loading branch information
1 parent
dc5dce0
commit 045e8c9
Showing
11 changed files
with
188 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const dmobValidator = async (response: Response): Promise<boolean> => { | ||
const { allowance } = await response.json(); | ||
return allowance > 0; | ||
}; | ||
export const backendValidator = async ( | ||
response: Response | ||
): Promise<boolean> => { | ||
const ret = await response.text(); | ||
return ret === "OK"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react"; | ||
import { SERVICE_STATUS } from "../constants"; | ||
import { type ServiceStatusProps } from "../types"; | ||
|
||
export const ServiceStatusIndicator: React.FC<ServiceStatusProps> = ({ | ||
name, | ||
status | ||
}) => { | ||
return ( | ||
<div> | ||
<span>{name} is currently: </span> | ||
<span>{SERVICE_STATUS[status]}</span> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
export const config = { | ||
apiUri: import.meta.env.VITE_API_URI || "http://localhost:4000" | ||
apiUri: import.meta.env.VITE_API_URI || "http://localhost:4000", | ||
serviceUrls: { | ||
backend: | ||
import.meta.env.VITE_BACKEND_SERVICE_URI || | ||
"https://fp-core.6omfj573u6naa.us-east-2.cs.amazonlightsail.com/health", | ||
ldnBot: import.meta.env.VITE_LDN_BOT_SERVICE_URI || "http://localhost:4002", | ||
ssaBot: import.meta.env.VITE_SSA_BOT_SERVICE_URI || "http://localhost", | ||
dmobApi: | ||
import.meta.env.VITE_DMOB_API_URI || | ||
"https://api.filplus.d.interplanetary.one/public/api/getAllowanceAssignedToLdnV3InLast2Weeks" | ||
}, | ||
dmobApiKey: import.meta.env.VITE_DMOB_API_KEY || "" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useEffect, useState } from "react"; | ||
import { checkServiceStatus } from "../api"; | ||
import { | ||
type Validator, | ||
type CheckServiceStatusOptions, | ||
ServiceStatus | ||
} from "../types"; | ||
|
||
export const useServiceStatus = ( | ||
url: string, | ||
validator: Validator, | ||
options?: CheckServiceStatusOptions | ||
): ServiceStatus => { | ||
const [status, setStatus] = useState(ServiceStatus.Checking); | ||
|
||
useEffect(() => { | ||
if (!url) { | ||
setStatus(ServiceStatus.Offline); | ||
return; | ||
} | ||
|
||
// Fetch and validate | ||
checkServiceStatus(url, validator, options) | ||
.then(serviceStatus => { | ||
setStatus(serviceStatus); | ||
}) | ||
.catch(error => { | ||
console.error("There was an error checking the service status:", error); | ||
setStatus(ServiceStatus.Offline); | ||
}); | ||
}, [url, validator, options]); | ||
|
||
return status; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { backendValidator, dmobValidator } from "../api/validators"; | ||
import { useServiceStatus } from "../hooks/useServiceStatus"; | ||
import { ServiceStatusIndicator } from "../components/ServiceStatusIndicator"; | ||
import { config } from "../config"; | ||
|
||
const Status = () => { | ||
const backendStatus = useServiceStatus( | ||
config.serviceUrls.backend, | ||
backendValidator | ||
); | ||
const dmobStatus = useServiceStatus( | ||
config.serviceUrls.dmobApi, | ||
dmobValidator, | ||
{ apiKey: config.dmobApiKey } | ||
); | ||
// const ldnBotStatus = useServiceStatus( | ||
// config.serviceUrls.dmobApi, | ||
// dmobValidator | ||
// ); | ||
// const ssaBotStatus = useServiceStatus( | ||
// config.serviceUrls.dmobApi, | ||
// dmobValidator | ||
// ); | ||
return ( | ||
<div className="flex flex-col"> | ||
<ServiceStatusIndicator name="Backend" status={backendStatus} /> | ||
<ServiceStatusIndicator name="Dmob API" status={dmobStatus} /> | ||
{/* <ServiceStatusIndicator name="Ldn Bot" status={ldnBotStatus} /> | ||
<ServiceStatusIndicator name="SSA Bot" status={ssaBotStatus} /> */} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Status; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters