Skip to content
Snippets Groups Projects
Commit 5f527880 authored by Saket Agrahari's avatar Saket Agrahari
Browse files

testing cross-origin http issue

parent 0a1df58c
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [0.1] - yyyy-mm-dd ## [0.1] - 2022-11-07
- initial skeleton - Initial skeleton - First Release
- COMP-2 Prototype Data only Service Matrix
- COMP-31 Baseline React routing structure
Source diff could not be displayed: it is too large. Options to address this: view the blob.
import React, {useState,useEffect} from 'react'; import React, {useState,useEffect} from 'react';
import {Nren, Service, ServiceMatrix} from "./Schema";
const api_url = window.location.origin; const api_url = window.location.origin;
...@@ -7,34 +8,54 @@ const api_url = window.location.origin; ...@@ -7,34 +8,54 @@ const api_url = window.location.origin;
function AnnualReport(): JSX.Element { function AnnualReport(): JSX.Element {
const [nrens, setNrens] = useState<any[]>([]); function api<T>(url: string, options: RequestInit): Promise<T> {
return fetch(url, options)
.then((response) => {
console.log(response)
if (!response.ok) {
return response.text().then((message) => {
console.error(`Failed to load datax: ${message}`, response.status);
throw new Error("The data could not be loaded, check the logs for details.");
});
}
return response.json() as Promise<T>;
})
}
const [nrens, setNrens] = useState<Nren[]>();
const [services, setServices] = useState<Service[][]>();
useEffect(() => { useEffect(() => {
async function loadData() { // let timeoutRef = 0;
const response = await fetch(api_url+'/service-matrix',{ const loadData = () => {
headers: { api<ServiceMatrix>(api_url+'/service-matrix',{
"Access-Control-Allow-Origin": "*", referrerPolicy: "unsafe-url",
"Content-Type": "text/plain" headers: {
} "Access-Control-Allow-Origin": "*",
} "Content-Type": "text/plain"
); }
const rsp_json = await response.json(); })
.then((serviceMatrix :ServiceMatrix)=>{
console.log('got response==>nrens');
console.log(serviceMatrix.nrens);
console.log('got response==>service');
console.log(serviceMatrix.services);
console.log(rsp_json.nrens) setNrens(serviceMatrix.nrens)
setNrens(rsp_json.nrens) setServices(serviceMatrix.services)
console.log('got response'); })
} }
loadData(); loadData()
}, []); }, []);
return ( return (
<div> <div>
<h1>Annual Report</h1> <h1>Annual Report</h1>
{nrens.map(nren=>( {nrens?.map(nren=>(
<h4 key={nren.nren_id}>{nren.name}</h4> <h4 key={nren.nren_id}>{nren.name}</h4>
))} ))}
</div> </div>
); );
} }
export default AnnualReport; export default AnnualReport;
\ No newline at end of file
...@@ -21,11 +21,11 @@ function Navigation(): JSX.Element { ...@@ -21,11 +21,11 @@ function Navigation(): JSX.Element {
<li>Annual Report</li> <li>Annual Report</li>
</Link> </Link>
<Link style={navStyle} to="/analysis"> <Link style={navStyle} to="/analysis">
<li>Data Annalysis</li> <li>Data Analysis</li>
</Link> </Link>
</ul> </ul>
</nav> </nav>
); );
} }
export default Navigation; export default Navigation;
\ No newline at end of file
export interface ServiceMatrix {
key: string,
nrens: Nren[],
services: Service[][]
}
export interface Nren {
name: string
nren_id:number
tags: string[]
}
export interface Service {
compendium_id: number,
country_code:string,
country_name:string,
created_at:Date,
id:number,
identifier:string,
kpi: string[],
nren_abbreviation:string
nren_id:number,
public:boolean,
question_id:number,
question_style:string,
response_id:number,
short:string,
status:number,
tags:string[],
title:string,
title_detailed:string,
updated_at:Date,
url:string,
value:string
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment