tactical nuke..no json :(
This commit is contained in:
@@ -228,28 +228,17 @@ async fn fetch_commit(url: &'static str) -> Result<String, FetchError> {
|
||||
Ok(text.as_string().unwrap())
|
||||
}
|
||||
|
||||
async fn fetch_driver(url: &'static str) -> Result<CommonDriver, FetchError> {
|
||||
async fn fetch_driver(url: &'static str) -> Result<String, FetchError> {
|
||||
let mut opts = RequestInit::new();
|
||||
opts.method("GET");
|
||||
//Available request modes: Cors, NoCors, SameOrigin
|
||||
opts.mode(RequestMode::NoCors); //NoCors because cors simply doesn't work here
|
||||
|
||||
opts.mode(RequestMode::Cors); //Cors is required for fetch to work
|
||||
//initialise request
|
||||
let request = Request::new_with_str_and_init(url, &opts)?;
|
||||
//api header for json
|
||||
request.headers().set("Accept", "application/json")?;
|
||||
|
||||
let window = web_sys::window().unwrap();
|
||||
let window = gloo::utils::window();
|
||||
let resp_value = JsFuture::from(window.fetch_with_request(&request)).await?;
|
||||
assert!(resp_value.is_instance_of::<Response>());
|
||||
let resp: Response = resp_value.dyn_into().unwrap();
|
||||
|
||||
//parsing Json response
|
||||
let fetched_json = JsFuture::from(resp.json()?).await?;
|
||||
log!(fetched_json.clone());
|
||||
let fetched_json: JsValue = fetched_json.into();
|
||||
//parsing into CommonDriver struct
|
||||
let fetched_json: CommonDriver = fetched_json.into_serde().unwrap();
|
||||
Ok(fetched_json)
|
||||
let text = JsFuture::from(resp.text()?).await?;
|
||||
Ok(text.as_string().unwrap())
|
||||
}
|
||||
|
||||
//renders components above
|
||||
|
||||
Reference in New Issue
Block a user