Skip browser cache & match new server response

This commit is contained in:
0x1eef 2023-10-01 08:42:21 -03:00
parent 7a2c1c22b8
commit 4c5488108c
3 changed files with 17 additions and 16 deletions

View file

@ -7,6 +7,7 @@ export function useWebService(): [Maybe<TResponse>, Maybe<Error>] {
const endpoint = "https://wtfismyip.com/json";
const [response, setResponse] = useState<Maybe<TResponse>>(null);
const [error, setError] = useState<Maybe<Error>>(null);
const options: RequestInit = {cache: "no-store"};
function receive(res: Response) {
if (res.status === 200) {
@ -18,7 +19,7 @@ export function useWebService(): [Maybe<TResponse>, Maybe<Error>] {
}
useEffect(() => {
fetch(endpoint)
fetch(endpoint, options)
.then(receive)
.then((json) => setResponse(Response(json)))
.catch((err) => setError(err));

View file

@ -7,21 +7,21 @@ export type TResponse = {
};
export type TServerResponse = {
YourFuckingIPAddress: string;
YourFuckingISP: string;
YourFuckingCity: string;
YourFuckingCountry: string;
YourFuckingTorExit: boolean;
YourIPAddress: string;
YourISP: string;
YourCity: string;
YourCountry: string;
YourTorExit: boolean;
};
export function Response(res: TServerResponse): TResponse {
const self = Object.create(null);
self.IPAddress = res.YourFuckingIPAddress;
self.ISP = res.YourFuckingISP;
self.City = res.YourFuckingCity;
self.Country = res.YourFuckingCountry;
self.isTorExitNode = res.YourFuckingTorExit;
self.IPAddress = res.YourIPAddress;
self.ISP = res.YourISP;
self.City = res.YourCity;
self.Country = res.YourCountry;
self.isTorExitNode = res.YourTorExit;
return self;
}

View file

@ -4,11 +4,11 @@ export function success(_path: RequestInfo | URL, _options?: RequestInit) {
const json = () => (
new Promise<TServerResponse>((resolve) => (
resolve({
YourFuckingIPAddress: "127.0.0.1",
YourFuckingISP: "FooBar Ltd",
YourFuckingCity: "Foo City",
YourFuckingCountry: "United States of FooBar",
YourFuckingTorExit: false
YourIPAddress: "127.0.0.1",
YourISP: "FooBar Ltd",
YourCity: "Foo City",
YourCountry: "United States of FooBar",
YourTorExit: false
})
)
));